@@ -451,7 +451,7 @@ public function fieldBasedAggregation($name, $field, $type = "terms", $parentPat
451451 * nodes = ${Search....aggregation("color", this.aggregationDefinition).execute()}
452452 *
453453 * Access all aggregation data with {nodes.aggregations} in your fluid template
454- *
454+ *
455455 * @param string $name
456456 * @param array $aggregationDefinition
457457 * @param null $parentPath
@@ -501,6 +501,64 @@ protected function addSubAggregation($parentPath, $name, $aggregationConfigurati
501501 return $ this ;
502502 }
503503
504+ /**
505+ * This method is used to create a simple term suggestion.
506+ *
507+ * Example Usage of a term suggestion
508+ *
509+ * nodes = ${Search....termSuggestions("aTerm")}
510+ *
511+ * Access all suggestions data with {nodes.suggestions} in your fluid template
512+ *
513+ * @param string $text
514+ * @param string $field
515+ * @param string $name
516+ * @return $this
517+ */
518+ public function termSuggestions ($ text , $ field = '_all ' , $ name = 'suggestions ' )
519+ {
520+ $ suggestionDefinition = [
521+ 'text ' => $ text ,
522+ 'term ' => [
523+ 'field ' => $ field
524+ ]
525+ ];
526+
527+ $ this ->suggestions ($ name , $ suggestionDefinition );
528+ return $ this ;
529+ }
530+
531+ /**
532+ * This method is used to create any kind of suggestion.
533+ *
534+ * Example Usage of a term suggestion for the fulltext search
535+ *
536+ * suggestionDefinition = TYPO3.TypoScript:RawArray {
537+ * text = "some text"
538+ * terms = TYPO3.TypoScript:RawArray {
539+ * field = "body"
540+ * }
541+ * }
542+ *
543+ * nodes = ${Search....suggestion("my-suggestions", this.suggestionDefinition).execute()}
544+ *
545+ * Access all suggestions data with {nodes.suggestions} in your fluid template
546+ *
547+ * @param string $name
548+ * @param array $suggestionDefinition
549+ * @return $this
550+ */
551+ public function suggestions ($ name , array $ suggestionDefinition )
552+ {
553+ if (!array_key_exists ('suggest ' , $ this ->request )) {
554+ $ this ->request ['suggest ' ] = [];
555+ }
556+
557+ $ this ->request ['suggest ' ][$ name ] = $ suggestionDefinition ;
558+
559+ return $ this ;
560+ }
561+
504562 /**
505563 * Get the ElasticSearch request as we need it
506564 *
0 commit comments