Skip to content

Commit 98065d3

Browse files
committed
BUGFIX: Respect content dimension for suggestions
As the node identifier is the same for all node variants the resulting suggestions were always retrieved from the default dimension. Now the dimension combination is also sent to the suggestion controller.
1 parent 8370549 commit 98065d3

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

Classes/Controller/SuggestController.php

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

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryResult;
1615
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1716
use Neos\Cache\Frontend\VariableFrontend;
18-
use Neos\ContentRepository\Domain\Model\NodeInterface;
1917
use Neos\Flow\Annotations as Flow;
2018
use Neos\Flow\Mvc\Controller\ActionController;
2119
use Neos\Flow\Mvc\View\JsonView;
@@ -52,10 +50,11 @@ class SuggestController extends ActionController
5250

5351
/**
5452
* @param string $contextNodeIdentifier
53+
* @param string $dimensionCombination
5554
* @param string $term
5655
* @return void
5756
*/
58-
public function indexAction($contextNodeIdentifier, $term)
57+
public function indexAction($contextNodeIdentifier, $dimensionCombination, $term)
5958
{
6059
$result = [
6160
'completions' => [],
@@ -68,7 +67,7 @@ public function indexAction($contextNodeIdentifier, $term)
6867
return;
6968
}
7069

71-
$requestJson = $this->buildRequestForTerm($term, $contextNodeIdentifier);
70+
$requestJson = $this->buildRequestForTerm($contextNodeIdentifier, $dimensionCombination, $term);
7271

7372
try {
7473
$response = $this->elasticSearchClient->getIndex()->request('POST', '/_search', [], $requestJson)->getTreatedContent();
@@ -84,19 +83,20 @@ public function indexAction($contextNodeIdentifier, $term)
8483
/**
8584
* @param string $term
8685
* @param string $contextNodeIdentifier
86+
* @param string $dimensionCombination
8787
* @return ElasticSearchQueryBuilder
8888
*/
89-
protected function buildRequestForTerm($term, $contextNodeIdentifier)
89+
protected function buildRequestForTerm($contextNodeIdentifier, $dimensionCombination, $term)
9090
{
91+
$cacheKey = $contextNodeIdentifier . '-' . md5($dimensionCombination);
9192
$termPlaceholder = '---term-soh2gufuNi---';
9293
$term = strtolower($term);
9394

9495
// The suggest function only works well with one word
9596
$suggestTerm = explode(' ', $term)[0];
9697

97-
if(!$this->elasticSearchQueryTemplateCache->has($contextNodeIdentifier)) {
98-
99-
$contentContext = $this->createContentContext('live', []);
98+
if(!$this->elasticSearchQueryTemplateCache->has($cacheKey)) {
99+
$contentContext = $this->createContentContext('live', json_decode($dimensionCombination, true));
100100
$contextNode = $contentContext->getNodeByIdentifier($contextNodeIdentifier);
101101

102102
/** @var ElasticSearchQueryBuilder $query */
@@ -135,7 +135,7 @@ protected function buildRequestForTerm($term, $contextNodeIdentifier)
135135

136136
$this->elasticSearchQueryTemplateCache->set($contextNodeIdentifier, $requestTemplate);
137137
} else {
138-
$requestTemplate = $this->elasticSearchQueryTemplateCache->get($contextNodeIdentifier);
138+
$requestTemplate = $this->elasticSearchQueryTemplateCache->get($cacheKey);
139139
}
140140

141141
return str_replace($termPlaceholder, $suggestTerm, $requestTemplate);

Resources/Private/Fusion/SearchPlugin.fusion

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ prototype(Flowpack.SearchPlugin:Search) < prototype(Neos.Neos:Content) {
3333

3434
prototype(Flowpack.SearchPlugin:Search.Form) < prototype(Neos.Fusion:Template) {
3535
node = ${site}
36-
36+
dimensionCombination = ${Json.stringify(this.node.dimensions)}
3737
templatePath = 'resource://Flowpack.SearchPlugin/Private/Templates/NodeTypes/Search.Form.html'
38+
inputClassNames = ''
3839
searchWord = ${request.arguments.search}
3940
}
4041

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<form method="GET">
2-
<input type="search" name="search" value="{searchWord}" placeholder="{f:translate(id: 'search', package: 'Flowpack.SearchPlugin')}" data-autocomplete-source="{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json', absolute: 1, arguments: {contextNode: node.identifier})}"/>
2+
<input type="search" name="search" value="{searchWord}" class="{inputClassNames}"
3+
placeholder="{f:translate(id: 'search', package: 'Flowpack.SearchPlugin')}"
4+
data-autocomplete-source="{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json', absolute: 1, arguments: {contextNodeIdentifier: node.identifier, dimensionCombination: dimensionCombination})}"/>
35
<button type="submit">{f:translate(id: 'search', package: 'Flowpack.SearchPlugin')}</button>
46
</form>

0 commit comments

Comments
 (0)