Classes/Eel/SearchResultHelper.php
public function didYouMean(ElasticSearchQueryResult $searchResult, float $scoreThreshold = 0.7, string $suggestionName = 'suggestions'): string
    {
        $maxScore = 0;
        $suggestionParts = [];

        foreach ($searchResult->getSuggestions()[$suggestionName] as $suggestion) {
            if (array_key_exists('options', $suggestion) && !empty($suggestion['options'])) {
                $bestSuggestion = current($suggestion['options']);
                $maxScore = $bestSuggestion['score'] > $maxScore ? $bestSuggestion['score'] : $maxScore;
                $suggestionParts[] = $bestSuggestion['text'];
            } else {
                $suggestionParts[] = $suggestion['text'];
            }
        }
        if ($maxScore >= $scoreThreshold) {
            return implode(' ', $suggestionParts);
        }

        return '';
    }
public function didYouMean(ElasticSearchQueryResult $searchResult, float $scoreThreshold = 0.7, string $suggestionName = 'suggestions'): string
    {
        $maxScore = 0;
        $suggestionParts = [];

        foreach ($searchResult->getSuggestions()[$suggestionName] as $suggestion) {
            if (array_key_exists('options', $suggestion) && !empty($suggestion['options'])) {
                $bestSuggestion = current($suggestion['options']);
                $maxScore = $bestSuggestion['score'] > $maxScore ? $bestSuggestion['score'] : $maxScore;
                $suggestionParts[] = $bestSuggestion['text'];
            } else {
                $suggestionParts[] = $suggestion['text'];
            }
        }
        if ($maxScore >= $scoreThreshold) {
            return implode(' ', $suggestionParts);
        }

        return '';
    }
public function didYouMean ( ElasticSearchQueryResult $ searchResult , float $ scoreThreshold = 0.7 , string $ suggestionName = 'suggestions' ) : string { $ maxScore = 0 ; $ suggestionParts = [ ] ; foreach ( $ searchResult -> getSuggestions ( ) [ $ suggestionName ] as $ suggestion ) { if ( array_key_exists ( 'options' , $ suggestion ) && ! empty ( $ suggestion [ 'options' ] ) ) { $ bestSuggestion = current ( $ suggestion [ 'options' ] ) ; $ maxScore = $ bestSuggestion [ 'score' ] > $ maxScore ? $ bestSuggestion [ 'score' ] : $ maxScore ; $ suggestionParts [ ] = $ bestSuggestion [ 'text' ] ; } else { $ suggestionParts [ ] = $ suggestion [ 'text' ] ; } } if ( $ maxScore >= $ scoreThreshold ) { return implode ( ' ' , $ suggestionParts ) ; } return '' ; }
The "didYouMean" operation processes the previously defined suggestion by extracting
and concatenating the best guess for each word given in the search term.
A threshold can be given as second parameter. If none of the suggestions reaches this
threshold, an empty string is returned.

Example::

searchQuery = ${Search.query(site).fulltext('noes cms').termSuggestions('noes cms')}
didYouMean = ${SearchResult.didYouMean(this.searchQuery.execute(), 0.5)}

@param ElasticSearchQueryResult $searchResult The result of an elastic search query
@param float $scoreThreshold The minimum required score to return the suggestion
@param string $suggestionName The suggestion name which was given in the suggestion definition
@return string
The didYouMean operation processes the previously defined suggestion by extracting and concatenating the best guess for each word given in the search term . A threshold can be given as second parameter . If none of the suggestions reaches this threshold an empty string is returned .