Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from v-technologies/feature-criteria-not-terms
Browse files Browse the repository at this point in the history
Implemetation of not terms criteria
  • Loading branch information
fbourigault committed Jul 15, 2015
2 parents cb881b2 + 982f3f5 commit a6df023
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/Simples/Request/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,35 @@ protected function _prepare_match() {
return $return;
}

/**
* Prepare for a "not_terms" clause
*
* @return array
*/
protected function _prepare_not_terms() {
$data = $this->get();

if (!isset($data['in']) || !isset($data['value'])) {
throw new Simples_Request_Exception('Key "in" or "value" empty', $data) ;
}

$return = array(
'bool' => array(
'must_not' => array(),
),
);

foreach((array)$data['in'] as $in) {
$return['bool']['must_not'][] = array(
'terms' => array(
$in => $data['value'],
),
);
}

return $return;
}

/**
* Prepare for a "term" clause.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/Simples/Request/Search/CriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ public function testNested() {
), $criteria->to('array'));
}

public function testNotTerms() {
$criteria = new TestCriteria(array(
'in' => 'ids',
'values' => array('1', '2', '3')
), array('type' => 'not_terms'));
$res = $criteria->to('array') ;
$expected = array(
'bool' => array(
'must_not' => array(
array(
'terms' => array(
'ids' => array('1', '2', '3')
)
)
),
),
);
$this->assertEquals($expected, $res) ;
}

/**
* @dataProvider providerNestedException
* @expectedException Simples_Request_Exception
Expand Down

0 comments on commit a6df023

Please sign in to comment.