Skip to content

Commit ad977d9

Browse files
committed
FEATURE: Expose clauseType for comparation methods
1 parent 0a6aee8 commit ad977d9

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,55 +238,59 @@ public function exactMatch($propertyName, $value)
238238
*
239239
* @param string $propertyName Name of the property
240240
* @param mixed $value Value for comparison
241+
* @param string $clauseType one of must, should, must_not
241242
* @return ElasticSearchQueryBuilder
242-
* @api
243243
* @throws QueryBuildingException
244+
* @api
244245
*/
245-
public function greaterThan($propertyName, $value)
246+
public function greaterThan($propertyName, $value, string $clauseType = 'must')
246247
{
247-
return $this->queryFilter('range', [$propertyName => ['gt' => $this->convertValue($value)]]);
248+
return $this->queryFilter('range', [$propertyName => ['gt' => $this->convertValue($value)]], $clauseType);
248249
}
249250

250251
/**
251252
* add a range filter (gte) for the given property
252253
*
253254
* @param string $propertyName Name of the property
254255
* @param mixed $value Value for comparison
256+
* @param string $clauseType one of must, should, must_not
255257
* @return ElasticSearchQueryBuilder
256258
* @throws QueryBuildingException
257259
* @api
258260
*/
259-
public function greaterThanOrEqual($propertyName, $value)
261+
public function greaterThanOrEqual($propertyName, $value, string $clauseType = 'must')
260262
{
261-
return $this->queryFilter('range', [$propertyName => ['gte' => $this->convertValue($value)]]);
263+
return $this->queryFilter('range', [$propertyName => ['gte' => $this->convertValue($value)]], $clauseType);
262264
}
263265

264266
/**
265267
* add a range filter (lt) for the given property
266268
*
267269
* @param string $propertyName Name of the property
268270
* @param mixed $value Value for comparison
271+
* @param string $clauseType one of must, should, must_not
269272
* @return ElasticSearchQueryBuilder
270273
* @api
271274
* @throws QueryBuildingException
272275
*/
273-
public function lessThan($propertyName, $value)
276+
public function lessThan($propertyName, $value, string $clauseType = 'must')
274277
{
275-
return $this->queryFilter('range', [$propertyName => ['lt' => $this->convertValue($value)]]);
278+
return $this->queryFilter('range', [$propertyName => ['lt' => $this->convertValue($value)]], $clauseType);
276279
}
277280

278281
/**
279282
* add a range filter (lte) for the given property
280283
*
281284
* @param string $propertyName Name of the property
282285
* @param mixed $value Value for comparison
286+
* @param string $clauseType one of must, should, must_not
283287
* @return ElasticSearchQueryBuilder
284288
* @throws QueryBuildingException
285289
* @api
286290
*/
287-
public function lessThanOrEqual($propertyName, $value)
291+
public function lessThanOrEqual($propertyName, $value, string $clauseType = 'must')
288292
{
289-
return $this->queryFilter('range', [$propertyName => ['lte' => $this->convertValue($value)]]);
293+
return $this->queryFilter('range', [$propertyName => ['lte' => $this->convertValue($value)]], $clauseType);
290294
}
291295

292296
/**
@@ -299,11 +303,11 @@ public function lessThanOrEqual($propertyName, $value)
299303
* @param string $filterType
300304
* @param mixed $filterOptions
301305
* @param string $clauseType one of must, should, must_not
302-
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException
306+
* @throws QueryBuildingException
303307
* @return ElasticSearchQueryBuilder
304308
* @api
305309
*/
306-
public function queryFilter($filterType, $filterOptions, $clauseType = 'must')
310+
public function queryFilter($filterType, $filterOptions, string $clauseType = 'must')
307311
{
308312
$this->request->queryFilter($filterType, $filterOptions, $clauseType);
309313

@@ -317,7 +321,7 @@ public function queryFilter($filterType, $filterOptions, $clauseType = 'must')
317321
*
318322
* @param string $path
319323
* @param array $data
320-
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException
324+
* @throws QueryBuildingException
321325
* @return ElasticSearchQueryBuilder
322326
*/
323327
public function appendAtPath($path, array $data)

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ Furthermore, the following operators are supported:
123123

124124
* `nodeType('Your.Node:Type')`
125125
* `exactMatch('propertyName', value)` -- supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
126-
* `greaterThan('propertyName', value)` -- range filter with property values greater than the given value
127-
* `greaterThanOrEqual('propertyName', value)` -- range filter with property values greater than or equal to the given value
128-
* `lessThan('propertyName', value)` -- range filter with property values less than the given value
129-
* `lessThanOrEqual('propertyName', value)` -- range filter with property values less than or equal to the given value
126+
* `greaterThan('propertyName', value, [clauseType])` -- range filter with property values greater than the given value
127+
* `greaterThanOrEqual('propertyName', value, [clauseType])` -- range filter with property values greater than or equal to the given value
128+
* `lessThan('propertyName', value, [clauseType])` -- range filter with property values less than the given value
129+
* `lessThanOrEqual('propertyName', value, [clauseType])` -- range filter with property values less than or equal to the given value
130130
* `sortAsc('propertyName')` and `sortDesc('propertyName')` -- can also be used multiple times, e.g. `sortAsc('tag').sortDesc(`date')`
131131
will first sort by tag ascending, and then by date descending.
132132
* `limit(5)` -- only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default)
@@ -135,7 +135,9 @@ Furthermore, the following operators are supported:
135135

136136
Furthermore, there is a more low-level operator which can be used to add arbitrary Elasticsearch filters:
137137

138-
* `queryFilter("filterType", {option1: "value1"})`
138+
* `queryFilter("filterType", {option1: "value1"}, [clauseType])`
139+
140+
The optional argument `clauseType` defaults to "must" and can be used to specify the boolean operator of the [bool query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html). It has to be one of `must`, `should`, `must_not` or `filter`.
139141

140142
At lowest level, there is the `request` operator which allows to modify the request in arbitrary manner. Note that the existing request is merged with the passed-in type in case it is an array:
141143

0 commit comments

Comments
 (0)