@@ -56,13 +56,13 @@ public function initializeObject()
5656 }
5757
5858 /**
59+ * @param string $term
5960 * @param string $contextNodeIdentifier
6061 * @param string $dimensionCombination
61- * @param string $term
6262 * @return void
6363 * @throws QueryBuildingException
6464 */
65- public function indexAction ($ contextNodeIdentifier , $ dimensionCombination , $ term )
65+ public function indexAction ($ term , $ contextNodeIdentifier , $ dimensionCombination = null )
6666 {
6767 if ($ this ->elasticSearchClient === null ) {
6868 throw new \RuntimeException ('The SuggestController needs an ElasticSearchClient, it seems you run without the flowpack/elasticsearch-contentrepositoryadaptor package, though. ' , 1487189823 );
@@ -79,14 +79,14 @@ public function indexAction($contextNodeIdentifier, $dimensionCombination, $term
7979 return ;
8080 }
8181
82- $ requestJson = $ this ->buildRequestForTerm ($ contextNodeIdentifier , $ dimensionCombination , $ term );
82+ $ requestJson = $ this ->buildRequestForTerm ($ term , $ contextNodeIdentifier , $ dimensionCombination );
8383
8484 try {
8585 $ response = $ this ->elasticSearchClient ->getIndex ()->request ('POST ' , '/_search ' , [], $ requestJson )->getTreatedContent ();
8686 $ result ['completions ' ] = $ this ->extractCompletions ($ response );
8787 $ result ['suggestions ' ] = $ this ->extractSuggestions ($ response );
8888 } catch (\Exception $ e ) {
89- $ result ['errors ' ] = ['Could not execute query ' ];
89+ $ result ['errors ' ] = ['Could not execute query: ' . $ e -> getMessage () ];
9090 }
9191
9292 $ this ->view ->assign ('value ' , $ result );
@@ -99,7 +99,7 @@ public function indexAction($contextNodeIdentifier, $dimensionCombination, $term
9999 * @return ElasticSearchQueryBuilder
100100 * @throws QueryBuildingException
101101 */
102- protected function buildRequestForTerm ($ contextNodeIdentifier , $ dimensionCombination , $ term )
102+ protected function buildRequestForTerm ($ term , $ contextNodeIdentifier , $ dimensionCombination = null )
103103 {
104104 $ cacheKey = $ contextNodeIdentifier . '- ' . md5 ($ dimensionCombination );
105105 $ termPlaceholder = '---term-soh2gufuNi--- ' ;
@@ -109,8 +109,8 @@ protected function buildRequestForTerm($contextNodeIdentifier, $dimensionCombina
109109 // and the term is trimmed to alnum characters to avoid errors
110110 $ suggestTerm = preg_replace ('/[[:^alnum:]]/ ' , '' , explode (' ' , $ term )[0 ]);
111111
112- if (!$ this ->elasticSearchQueryTemplateCache ->has ($ cacheKey )) {
113- $ contentContext = $ this ->createContentContext ('live ' , json_decode ($ dimensionCombination , true ));
112+ if (!$ this ->elasticSearchQueryTemplateCache ->has ($ cacheKey )) {
113+ $ contentContext = $ this ->createContentContext ('live ' , $ dimensionCombination ? json_decode ($ dimensionCombination , true ) : [] );
114114 $ contextNode = $ contentContext ->getNodeByIdentifier ($ contextNodeIdentifier );
115115
116116 /** @var ElasticSearchQueryBuilder $query */
@@ -132,7 +132,7 @@ protected function buildRequestForTerm($contextNodeIdentifier, $dimensionCombina
132132 ]
133133 ])
134134 ->suggestions ('suggestions ' , [
135- 'text ' => $ termPlaceholder ,
135+ 'prefix ' => $ termPlaceholder ,
136136 'completion ' => [
137137 'field ' => '__suggestions ' ,
138138 'fuzzy ' => true ,
0 commit comments