1212 */
1313
1414use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryBuilder ;
15- use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryResult ;
1615use Flowpack \ElasticSearch \ContentRepositoryAdaptor \ElasticSearchClient ;
1716use Neos \Cache \Frontend \VariableFrontend ;
18- use Neos \ContentRepository \Domain \Model \NodeInterface ;
1917use Neos \Flow \Annotations as Flow ;
2018use Neos \Flow \Mvc \Controller \ActionController ;
2119use 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 );
0 commit comments