Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/InterNations/Component/Solr/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,40 @@ public function grp($expr = null, $type = null)
return new GroupExpression($args, $type);
}

/**
* Create AND grouped expression: (<expr1> AND <expr2> AND <expr3>)
*
* @param Expression|string $expr, ...
* @param string $type
* @return Expression
*/
public function andX($expr = null)
{
$args = func_get_args();
if (!$args) {
return null;
}

return new GroupExpression($args, GroupExpression::TYPE_AND);
}

/**
* Create OR grouped expression: (<expr1> OR <expr2> OR <expr3>)
*
* @param Expression|string $expr, ...
* @param string $type
* @return Expression
*/
public function orX($expr = null)
{
$args = func_get_args();
if (!$args) {
return null;
}

return new GroupExpression($args, GroupExpression::TYPE_OR);
}

/**
* Returns a query "*:*" which means find all if $expr is empty
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ public function testGroupingSingleParamAsArray()
$this->assertSame('("bar" "foo" "baz")', (string) $g);
}

public function testGroupingWithAndX()
{
$g = $this->eb->andX($this->eb->phrase('foo'), $this->eb->phrase('bar'), $this->eb->phrase('baz'));
$this->assertInstanceOf('InterNations\Component\Solr\Expression\GroupExpression', $g);
$this->assertSame('("foo" AND "bar" AND "baz")', (string) $g);
}

public function testGroupingWithOrX()
{
$g = $this->eb->orX($this->eb->phrase('foo'), $this->eb->phrase('bar'), $this->eb->phrase('baz'));
$this->assertInstanceOf('InterNations\Component\Solr\Expression\GroupExpression', $g);
$this->assertSame('("foo" OR "bar" OR "baz")', (string) $g);
}

public function testField()
{
$f = $this->eb->field('field', 'query');
Expand Down