Skip to content

Commit d8bd598

Browse files
committed
FEATURE: Add an exclude method to the ES query builder
Works basically as a negation of the exactMatch method
1 parent 00261be commit d8bd598

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,17 @@ public function exactMatch($propertyName, $value)
242242
return $this->queryFilter('term', [$propertyName => $this->convertValue($value)]);
243243
}
244244

245+
/**
246+
* @param string $propertyName
247+
* @param $value
248+
* @return ElasticSearchQueryBuilder
249+
* @throws QueryBuildingException
250+
*/
251+
public function exclude(string $propertyName, $value)
252+
{
253+
return $this->queryFilter('term', [$propertyName => $this->convertValue($value)], 'must_not');
254+
}
255+
245256
/**
246257
* add a range filter (gt) for the given property
247258
*

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ search underneath the current site node (like in the example above).
121121

122122
Furthermore, the following operators are supported:
123123

124+
As **value**, the following methods accept a simple type, a node object or a DateTime object.
125+
124126
* `nodeType('Your.Node:Type')`
125127
* `exactMatch('propertyName', value)` -- supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
128+
* `exclude('propertyName', value)` -- excludes results by property - the negation of exactMatch.
126129
* `greaterThan('propertyName', value, [clauseType])` -- range filter with property values greater than the given value
127130
* `greaterThanOrEqual('propertyName', value, [clauseType])` -- range filter with property values greater than or equal to the given value
128131
* `lessThan('propertyName', value, [clauseType])` -- range filter with property values less than the given value

0 commit comments

Comments
 (0)