Skip to content

Commit b699e46

Browse files
committed
FEATURE: Add Node-Type Filter
Create a method which allows to create a nodetype filter to include and exclude specific nodetypes
1 parent 2a7de69 commit b699e46

File tree

2 files changed

+67
-17
lines changed

2 files changed

+67
-17
lines changed

Classes/Eel/ElasticSearchQueryBuilder.php

+49
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,55 @@ public function nodeType(string $nodeType): QueryBuilderInterface
131131
return $this->queryFilter('term', ['neos_type_and_supertypes' => $nodeType]);
132132
}
133133

134+
/**
135+
* Filter multiple node types
136+
*
137+
* @param array $expectedNodeTypes NodeTypes that should be expected
138+
* @param array $excludedNodeTypes NodeTypes that should be excluded
139+
* @return ElasticSearchQueryBuilder
140+
* @throws QueryBuildingException
141+
* @api
142+
*/
143+
public function nodeTypeFilter(array $expectedNodeTypes, array $excludedNodeTypes): QueryBuilderInterface
144+
{
145+
$excludeShould = [];
146+
foreach ($excludedNodeTypes as $nodeType) {
147+
$excludeShould[] = [
148+
'term' => [
149+
'neos_type_and_supertypes' => $nodeType
150+
]
151+
];
152+
}
153+
if (!empty($excludeShould)) {
154+
$this->request->queryFilter(
155+
'bool',
156+
[
157+
'should' => $excludeShould
158+
],
159+
'must_not'
160+
);
161+
}
162+
163+
foreach ($expectedNodeTypes as $nodeType) {
164+
$includeShould[] = [
165+
'term' => [
166+
'neos_type_and_supertypes' => $nodeType
167+
]
168+
];
169+
}
170+
if (!empty($includeShould)) {
171+
$this->request->queryFilter(
172+
'bool',
173+
[
174+
'should' => $includeShould
175+
],
176+
'must'
177+
);
178+
}
179+
180+
return $this;
181+
}
182+
134183
/**
135184
* Sort descending by $propertyName
136185
*

README.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,24 @@ Furthermore, the following operators are supported:
427427

428428
As **value**, the following methods accept a simple type, a node object or a DateTime object.
429429

430-
| Query Operator | Description |
431-
|----------------|-------------|
432-
|`nodeType('Your.Node:Type')` |Filters on the given NodeType|
433-
|`exactMatch('propertyName', value)` |Supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`|
434-
|`exclude('propertyName', value)` |Excludes results by property - the negation of exactMatch.
435-
|`greaterThan('propertyName', value, [clauseType])` |Range filter with property values greater than the given value|
436-
|`greaterThanOrEqual('propertyName', value, [clauseType])`|Range filter with property values greater than or equal to the given value|
437-
|`lessThan('propertyName', value, [clauseType])` |Range filter with property values less than the given value|
438-
|`lessThanOrEqual('propertyName', value, [clauseType])`|Range filter with property values less than or equal to the given value|
439-
|`sortAsc('propertyName')` / `sortDesc('propertyName')`|Can also be used multiple times, e.g. `sortAsc('tag').sortDesc('date')` will first sort by tag ascending, and then by date descending.|
440-
|`limit(5)` |Only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default)|
441-
|`from(5)` |Return the results starting from the 6th one|
442-
|`prefix('propertyName', 'prefix', [clauseType])` |Adds a prefix filter on the given field with the given prefix|
443-
|`geoDistance(propertyName, geoPoint, distance, [clauseType])`. |Filters documents that include only hits that exists within a specific distance from a geo point.|
444-
|`fulltext('searchWord', options)` |Does a query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html) to the query_string. Recommendation: **use simpleQueryStringFulltext instead, as it yields better results and is more tolerant to user input**.|
445-
|`simpleQueryStringFulltext('searchWord', options)` |Does a simple_query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/8.3/query-dsl-simple-query-string-query.html) to the simple_query_string. Supports phrase matching like `"firstname lastname"` and tolerates broken input without exceptions (in contrast to `fulltext()`)|
446-
|`highlight(fragmentSize, fragmentCount, noMatchSize, field)` |Configure result highlighting for every fulltext field individually|
430+
| Query Operator | Description |
431+
|-----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
432+
| `nodeType('Your.Node:Type')` | Filters on the given NodeType |
433+
| `nodeTypeFilter(['Your.Node:Type'],['Your.ExcludedNode:Type'])` | Filters multiple NodeTypes |
434+
| `exactMatch('propertyName', value)` | Supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)` |
435+
| `exclude('propertyName', value)` | Excludes results by property - the negation of exactMatch. |
436+
| `greaterThan('propertyName', value, [clauseType])` | Range filter with property values greater than the given value |
437+
| `greaterThanOrEqual('propertyName', value, [clauseType])` | Range filter with property values greater than or equal to the given value |
438+
| `lessThan('propertyName', value, [clauseType])` | Range filter with property values less than the given value |
439+
| `lessThanOrEqual('propertyName', value, [clauseType])` | Range filter with property values less than or equal to the given value |
440+
| `sortAsc('propertyName')` / `sortDesc('propertyName')` | Can also be used multiple times, e.g. `sortAsc('tag').sortDesc('date')` will first sort by tag ascending, and then by date descending. |
441+
| `limit(5)` | Only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default) |
442+
| `from(5)` | Return the results starting from the 6th one |
443+
| `prefix('propertyName', 'prefix', [clauseType])` | Adds a prefix filter on the given field with the given prefix |
444+
| `geoDistance(propertyName, geoPoint, distance, [clauseType])`. | Filters documents that include only hits that exists within a specific distance from a geo point. |
445+
| `fulltext('searchWord', options)` | Does a query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/query-dsl-query-string-query.html) to the query_string. Recommendation: **use simpleQueryStringFulltext instead, as it yields better results and is more tolerant to user input**. |
446+
| `simpleQueryStringFulltext('searchWord', options)` | Does a simple_query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/8.3/query-dsl-simple-query-string-query.html) to the simple_query_string. Supports phrase matching like `"firstname lastname"` and tolerates broken input without exceptions (in contrast to `fulltext()`) |
447+
| `highlight(fragmentSize, fragmentCount, noMatchSize, field)` | Configure result highlighting for every fulltext field individually |
447448

448449
## Search Result Highlighting
449450

0 commit comments

Comments
 (0)