Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced Bool filter cache and cache key parameters support #725

Merged
merged 2 commits into from
Nov 20, 2014
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
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CHANGES

2014-11-20
- add cache control parameters support to Elastica\Filter\Bool

2014-11-13
- fixed reserved words in queries which composed of upper case letters (Util::replaceBooleanWords)

Expand Down
4 changes: 4 additions & 0 deletions lib/Elastica/Filter/Bool.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public function toArray()
$args['bool']['must_not'] = $this->_mustNot;
}

if (isset($args['bool'])) {
$args['bool'] = array_merge($args['bool'], $this->getParams());
}

return $args;
}

Expand Down
45 changes: 43 additions & 2 deletions test/lib/Elastica/Test/Filter/BoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Elastica\Test\Filter;

use Elastica\Filter\Terms;
use \Elastica\Query;
use Elastica\Filter\Bool;
use Elastica\Filter\Term;
Expand All @@ -10,8 +11,15 @@

class BoolTest extends BaseTest
{
public function testToArray()

/**
* @return array
*/
public function getTestToArrayData()
{
$out = array();

// case #0
$mainBool = new Bool();

$idsFilter1 = new Ids();
Expand Down Expand Up @@ -44,8 +52,41 @@ public function testToArray()
)
)
);
$out[] = array($mainBool, $expectedArray);

// case #1 _cache parameter should be supported
$bool = new Bool();
$terms = new Terms('field1', array('value1', 'value2'));
$termsNot = new Terms('field2', array('value1', 'value2'));
$bool->addMust($terms);
$bool->addMustNot($termsNot);
$bool->setCached(true);
$bool->setCacheKey('my-cache-key');
$expected = array(
'bool' => array(
'must' => array(
$terms->toArray()
),
'must_not' => array(
$termsNot->toArray()
),
'_cache' => true,
'_cache_key' => 'my-cache-key'
)
);
$out[] = array($bool, $expected);

return $out;
}

$this->assertEquals($expectedArray, $mainBool->toArray());
/**
* @dataProvider getTestToArrayData()
* @param Bool $bool
* @param array $expectedArray
*/
public function testToArray(Bool $bool, $expectedArray)
{
$this->assertEquals($expectedArray, $bool->toArray());
}

public function testBoolFilter()
Expand Down