Skip to content

Commit 2a36448

Browse files
authored
Merge pull request #2 from nlx-lars/bugfix/es-5-support
TASK: Adjust search to changes in Elasticsearch 5
2 parents 5934f90 + c42d689 commit 2a36448

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

Classes/Driver/Version5/Query/FilteredQuery.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,37 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version1;
15+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception;
1516

1617
/**
1718
* Default Filtered Query
1819
*/
1920
class FilteredQuery extends Version1\Query\FilteredQuery
2021
{
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function fulltext($searchWord)
27+
{
28+
$this->appendAtPath('query.bool.must', [
29+
'query_string' => [
30+
'query' => $searchWord
31+
]
32+
]);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function queryFilter($filterType, $filterOptions, $clauseType = 'must')
39+
{
40+
if (!in_array($clauseType, ['must', 'should', 'must_not'])) {
41+
throw new Exception\QueryBuildingException('The given clause type "' . $clauseType . '" is not supported. Must be one of "must", "should", "must_not".',
42+
1383716082);
43+
}
44+
45+
$this->appendAtPath('query.bool.filter.bool.' . $clauseType, [$filterType => $filterOptions]);
46+
}
47+
2148
}

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,10 @@ protected function convertHitsToNodes(array $hits)
728728
* we might be able to use https://github.com/elasticsearch/elasticsearch/issues/3300 as soon as it is merged.
729729
*/
730730
foreach ($hits['hits'] as $hit) {
731-
$nodePath = current($hit['fields']['__path']);
731+
$nodePath = $hit[isset($hit['fields']) ? 'fields' : '_source']['__path'];
732+
if (is_array($nodePath)) {
733+
$nodePath = current($nodePath);
734+
}
732735
$node = $this->contextNode->getNode($nodePath);
733736
if ($node instanceof NodeInterface && !isset($nodes[$node->getIdentifier()])) {
734737
$nodes[$node->getIdentifier()] = $node;

Configuration/Settings.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,35 @@ Flowpack:
7979
className: 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version5\Query\FilteredQuery'
8080
arguments:
8181
request:
82-
<<: *request_version1
82+
query:
83+
bool:
84+
must:
85+
- match_all:
86+
boost: 1.0 # force match_all to be an object
87+
filter:
88+
bool:
89+
must: []
90+
should: []
91+
must_not:
92+
- term:
93+
_hidden: true
94+
- range:
95+
_hiddenBeforeDateTime:
96+
gt: now
97+
- range:
98+
_hiddenAfterDateTime:
99+
lt: now
100+
_source:
101+
- '__path'
83102
unsupportedFieldsInCountRequest:
84-
<<: *unsupportedFieldsInCountRequest_version1
103+
- '_source'
104+
- 'sort'
105+
- 'from'
106+
- 'size'
107+
- 'highlight'
108+
- 'aggs'
109+
- 'aggregations'
110+
- 'suggest'
85111
document:
86112
className: 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version5\DocumentDriver'
87113
indexer:

0 commit comments

Comments
 (0)