Skip to content

Commit 9efa79f

Browse files
authored
Merge pull request #199 from kdambekalns/bugfix-get-current-document-take-two
BUGFIX: Include the context document in the query result
2 parents 6e0e7b0 + a44e258 commit 9efa79f

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,17 @@ public function query(NodeInterface $contextNode)
651651
// on indexing, the __parentPath is tokenized to contain ALL parent path parts,
652652
// e.g. /foo, /foo/bar/, /foo/bar/baz; to speed up matching.. That's why we use a simple "term" filter here.
653653
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html
654-
$this->queryFilter('term', ['__parentPath' => $contextNode->getPath()]);
654+
// another term filter against the path allows the context node itself to be found
655+
$this->queryFilter('bool', [
656+
'should' => [
657+
[
658+
'term' => ['__parentPath' => $contextNode->getPath()]
659+
],
660+
[
661+
'term' => ['__path' => $contextNode->getPath()]
662+
]
663+
]
664+
]);
655665

656666
//
657667
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function filterByNodeType()
140140
->log($this->getLogMessagePrefix(__METHOD__))
141141
->nodeType('TYPO3.Neos.NodeTypes:Page')
142142
->count();
143-
$this->assertEquals(3, $resultCount);
143+
$this->assertEquals(4, $resultCount);
144144
}
145145

146146
/**
@@ -166,7 +166,7 @@ public function limitDoesNotImpactCount()
166166
->limit(1);
167167

168168
$resultCount = $query->count();
169-
$this->assertEquals(3, $resultCount, 'Asserting the count query returns the total count.');
169+
$this->assertEquals(4, $resultCount, 'Asserting the count query returns the total count.');
170170
}
171171

172172
/**
@@ -198,7 +198,7 @@ public function fieldBasedAggregations()
198198

199199
$this->assertArrayHasKey($aggregationTitle, $result);
200200

201-
$this->assertCount(2, $result[$aggregationTitle]['buckets']);
201+
$this->assertCount(3, $result[$aggregationTitle]['buckets']);
202202

203203
$expectedChickenBucket = [
204204
'key' => 'chicken',
@@ -268,13 +268,13 @@ public function nodesWillBeSortedDesc()
268268
/** @var QueryResultInterface $result $node */
269269

270270
$this->assertInstanceOf(QueryResultInterface::class, $result);
271-
$this->assertCount(3, $result, 'The result should have 3 items');
272-
$this->assertEquals(3, $result->count(), 'Count should be 3');
271+
$this->assertCount(4, $result, 'The result should have 3 items');
272+
$this->assertEquals(4, $result->count(), 'Count should be 3');
273273

274274
$node = $result->getFirst();
275275

276276
$this->assertInstanceOf(NodeInterface::class, $node);
277-
$this->assertEquals('egg', $node->getProperty('title'), 'Asserting a desc sort order by property title');
277+
$this->assertEquals('welcome', $node->getProperty('title'), 'Asserting a desc sort order by property title');
278278
}
279279

280280
/**

Tests/Unit/Eel/ElasticSearchQueryBuilderTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,19 @@ public function basicRequestStructureTakesContextNodeIntoAccount()
111111
'bool' => [
112112
'must' => [
113113
0 => [
114-
'term' => [
115-
'__parentPath' => '/foo/bar'
114+
'bool' => [
115+
'should' => [
116+
0 => [
117+
'term' => [
118+
'__parentPath' => '/foo/bar'
119+
]
120+
],
121+
1 => [
122+
'term' => [
123+
'__path' => '/foo/bar'
124+
]
125+
]
126+
]
116127
]
117128
],
118129
1 => [

0 commit comments

Comments
 (0)