protected function addTopResultsToSuggestions(SearchRequest $searchRequest, $suggestions, array $additionalFilters) : array
    {
        $maxDocuments = $this->typoScriptConfiguration->getSuggestNumberOfTopResults();

        // perform the current search.
        $searchRequest->setResultsPerPage($maxDocuments);
        $searchRequest->setAdditionalFilters($additionalFilters);

        $didASecondSearch = false;
        $documents = [];

        $searchResultSet = $this->doASearch($searchRequest);
        $results = $searchResultSet->getSearchResults();
        if (count($results) > 0) {
            $documents = $this->addDocumentsWhenLimitNotReached($documents, $results, $maxDocuments);
        }

        $suggestionKeys = array_keys($suggestions);
        $bestSuggestion = reset($suggestionKeys);
        $bestSuggestionRequest = $searchRequest->getCopyForSubRequest();
        $bestSuggestionRequest->setRawQueryString($bestSuggestion);
        $bestSuggestionRequest->setResultsPerPage($maxDocuments);
        $bestSuggestionRequest->setAdditionalFilters($additionalFilters);

        // No results found, use first proposed suggestion to perform the search
        if (count($documents) === 0 && !empty($suggestions) && ($searchResultSet = $this->doASearch($bestSuggestionRequest)) && count($searchResultSet->getSearchResults()) > 0) {
            $didASecondSearch = true;
            $documentsToAdd = $searchResultSet->getSearchResults();
            $documents = $this->addDocumentsWhenLimitNotReached($documents, $documentsToAdd, $maxDocuments);
        }

        return $this->getResultArray($searchRequest, $suggestions, $documents, $didASecondSearch);
    }
protected function addTopResultsToSuggestions(SearchRequest $searchRequest, $suggestions, array $additionalFilters) : array
    {
        $maxDocuments = $this->typoScriptConfiguration->getSuggestNumberOfTopResults();

        // perform the current search.
        $searchRequest->setResultsPerPage($maxDocuments);
        $searchRequest->setAdditionalFilters($additionalFilters);

        $didASecondSearch = false;
        $documents = [];

        $searchResultSet = $this->doASearch($searchRequest);
        $results = $searchResultSet->getSearchResults();
        if (count($results) > 0) {
            $documents = $this->addDocumentsWhenLimitNotReached($documents, $results, $maxDocuments);
        }

        $suggestionKeys = array_keys($suggestions);
        $bestSuggestion = reset($suggestionKeys);
        $bestSuggestionRequest = $searchRequest->getCopyForSubRequest();
        $bestSuggestionRequest->setRawQueryString($bestSuggestion);
        $bestSuggestionRequest->setResultsPerPage($maxDocuments);
        $bestSuggestionRequest->setAdditionalFilters($additionalFilters);

        // No results found, use first proposed suggestion to perform the search
        if (count($documents) === 0 && !empty($suggestions) && ($searchResultSet = $this->doASearch($bestSuggestionRequest)) && count($searchResultSet->getSearchResults()) > 0) {
            $didASecondSearch = true;
            $documentsToAdd = $searchResultSet->getSearchResults();
            $documents = $this->addDocumentsWhenLimitNotReached($documents, $documentsToAdd, $maxDocuments);
        }

        return $this->getResultArray($searchRequest, $suggestions, $documents, $didASecondSearch);
    }
protected function addTopResultsToSuggestions ( SearchRequest $ searchRequest , $ suggestions , array $ additionalFilters ) : array { $ maxDocuments = $ this -> typoScriptConfiguration -> getSuggestNumberOfTopResults ( ) ; // perform the current search. $ searchRequest -> setResultsPerPage ( $ maxDocuments ) ; $ searchRequest -> setAdditionalFilters ( $ additionalFilters ) ; $ didASecondSearch = false ; $ documents = [ ] ; $ searchResultSet = $ this -> doASearch ( $ searchRequest ) ; $ results = $ searchResultSet -> getSearchResults ( ) ; if ( count ( $ results ) > 0 ) { $ documents = $ this -> addDocumentsWhenLimitNotReached ( $ documents , $ results , $ maxDocuments ) ; } $ suggestionKeys = array_keys ( $ suggestions ) ; $ bestSuggestion = reset ( $ suggestionKeys ) ; $ bestSuggestionRequest = $ searchRequest -> getCopyForSubRequest ( ) ; $ bestSuggestionRequest -> setRawQueryString ( $ bestSuggestion ) ; $ bestSuggestionRequest -> setResultsPerPage ( $ maxDocuments ) ; $ bestSuggestionRequest -> setAdditionalFilters ( $ additionalFilters ) ; // No results found, use first proposed suggestion to perform the search if ( count ( $ documents ) === 0 && ! empty ( $ suggestions ) && ( $ searchResultSet = $ this -> doASearch ( $ bestSuggestionRequest ) ) && count ( $ searchResultSet -> getSearchResults ( ) ) > 0 ) { $ didASecondSearch = true ; $ documentsToAdd = $ searchResultSet -> getSearchResults ( ) ; $ documents = $ this -> addDocumentsWhenLimitNotReached ( $ documents , $ documentsToAdd , $ maxDocuments ) ; } return $ this -> getResultArray ( $ searchRequest , $ suggestions , $ documents , $ didASecondSearch ) ; }
Determines the top results and adds them to the suggestions.

@param SearchRequest $searchRequest
@param array $suggestions
@param array $additionalFilters
@return array
Determines the top results and adds them to the suggestions .