Skip to content

Commit a3d5c0a

Browse files
authored
Merge pull request #292 from Flowpack/fix-upmerge
BUGFIX: fix upmerge gone wrong
2 parents 276f7f6 + d536d6d commit a3d5c0a

5 files changed

Lines changed: 36 additions & 25 deletions

File tree

Classes/Driver/QueryInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function size($size);
6969
public function from($size);
7070

7171
/**
72-
* Match the searchword against the fulltext index
72+
* Match the search word against the fulltext index
7373
*
7474
* @param string $searchWord
75+
* @param array $options Options to configure the query_string
7576
* @return void
7677
* @api
7778
*/
78-
public function fulltext($searchWord);
79+
public function fulltext(string $searchWord, array $options = []);
7980

8081
/**
8182
* Configure Result Highlighting. Only makes sense in combination with fulltext(). By default, highlighting is enabled.

Classes/Driver/Version1/Query/FilteredQuery.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public function from($size)
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function fulltext($searchWord)
56+
public function fulltext(string $searchWord, array $options = [])
5757
{
5858
$this->appendAtPath('query.filtered.query.bool.must', [
59-
'query_string' => [
60-
'query' => $searchWord
61-
]
59+
'query_string' => array_merge($options, ['query' => $searchWord])
6260
]);
6361
}
6462

Classes/Driver/Version5/Query/FilteredQuery.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class FilteredQuery extends Version1\Query\FilteredQuery
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function fulltext($searchWord)
26+
public function fulltext(string $searchWord, array $options = [])
2727
{
2828
$this->appendAtPath('query.bool.must', [
29-
'query_string' => [
30-
'query' => $searchWord
31-
]
29+
'query_string' => array_merge($options, ['query' => $searchWord])
3230
]);
3331
}
3432

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ public function from($from)
227227
*/
228228
public function exactMatch($propertyName, $value)
229229
{
230-
if ($value instanceof NodeInterface) {
231-
$value = $value->getIdentifier();
232-
}
233-
234-
return $this->queryFilter('term', [$propertyName => $value]);
230+
return $this->queryFilter('term', [$propertyName => $this->convertValue($value)]);
235231
}
236232

237233
/**
@@ -244,7 +240,7 @@ public function exactMatch($propertyName, $value)
244240
*/
245241
public function greaterThan($propertyName, $value)
246242
{
247-
return $this->queryFilter('range', [$propertyName => ['gt' => $value]]);
243+
return $this->queryFilter('range', [$propertyName => ['gt' => $this->convertValue($value)]]);
248244
}
249245

250246
/**
@@ -257,7 +253,7 @@ public function greaterThan($propertyName, $value)
257253
*/
258254
public function greaterThanOrEqual($propertyName, $value)
259255
{
260-
return $this->queryFilter('range', [$propertyName => ['gte' => $value]]);
256+
return $this->queryFilter('range', [$propertyName => ['gte' => $this->convertValue($value)]]);
261257
}
262258

263259
/**
@@ -270,7 +266,7 @@ public function greaterThanOrEqual($propertyName, $value)
270266
*/
271267
public function lessThan($propertyName, $value)
272268
{
273-
return $this->queryFilter('range', [$propertyName => ['lt' => $value]]);
269+
return $this->queryFilter('range', [$propertyName => ['lt' => $this->convertValue($value)]]);
274270
}
275271

276272
/**
@@ -283,7 +279,7 @@ public function lessThan($propertyName, $value)
283279
*/
284280
public function lessThanOrEqual($propertyName, $value)
285281
{
286-
return $this->queryFilter('range', [$propertyName => ['lte' => $value]]);
282+
return $this->queryFilter('range', [$propertyName => ['lte' => $this->convertValue($value)]]);
287283
}
288284

289285
/**
@@ -615,13 +611,14 @@ public function count()
615611
* Match the searchword against the fulltext index
616612
*
617613
* @param string $searchWord
614+
* @param array $options Options to configure the query_string, see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html
618615
* @return QueryBuilderInterface
619616
* @api
620617
*/
621-
public function fulltext($searchWord)
618+
public function fulltext($searchWord, array $options = [])
622619
{
623620
// We automatically enable result highlighting when doing fulltext searches. It is up to the user to use this information or not use it.
624-
$this->request->fulltext(trim(json_encode($searchWord), '"'));
621+
$this->request->fulltext(trim(json_encode($searchWord), '"'), $options);
625622
$this->request->highlight(150, 2);
626623

627624
return $this;
@@ -775,4 +772,21 @@ public function __call($method, array $arguments)
775772

776773
return $this;
777774
}
775+
776+
/**
777+
* @param mixed $value
778+
* @return mixed
779+
*/
780+
protected function convertValue($value)
781+
{
782+
if ($value instanceof NodeInterface) {
783+
return $value->getIdentifier();
784+
}
785+
786+
if ($value instanceof \DateTime) {
787+
return $value->format('Y-m-d\TH:i:sP');
788+
}
789+
790+
return $value;
791+
}
778792
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Neos Elasticsearch Adapter
44

5-
This project connects the Neos Content Repository (TYPO3CR) to Elasticsearch; enabling two
5+
This project connects the Neos Content Repository to Elasticsearch; enabling two
66
main functionalities:
77

88
* finding Nodes in Fusion / Eel by arbitrary queries
@@ -128,8 +128,8 @@ search underneath the current site node (like in the example above).
128128

129129
Furthermore, the following operators are supported:
130130

131-
* `nodeType("Your.Node:Type")`
132-
* `exactMatch('propertyName', value)`; supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
131+
* `nodeType('Your.Node:Type')`
132+
* `exactMatch('propertyName', value)` -- supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
133133
* `greaterThan('propertyName', value)` -- range filter with property values greater than the given value
134134
* `greaterThanOrEqual('propertyName', value)` -- range filter with property values greater than or equal to the given value
135135
* `lessThan('propertyName', value)` -- range filter with property values less than the given value
@@ -138,7 +138,7 @@ Furthermore, the following operators are supported:
138138
will first sort by tag ascending, and then by date descending.
139139
* `limit(5)` -- only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default)
140140
* `from(5)` -- return the results starting from the 6th one
141-
* `fulltext(...)` -- do a query_string query on the Fulltext Index
141+
* `fulltext('searchWord', options)` -- do a query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html) to the query_string
142142

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

0 commit comments

Comments
 (0)