You are here

protected function SearchApiSolrBackend::getAutocompleteSuggesterSuggestions in Search API Solr 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getAutocompleteSuggesterSuggestions()
  2. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getAutocompleteSuggesterSuggestions()

Get the term suggestions from the autocomplete query result.

Parameters

\Solarium\Core\Query\Result\ResultInterface $result: An autocomplete query result.

\Drupal\search_api_autocomplete\Suggestion\SuggestionFactory $suggestion_factory: The suggestion factory.

Return value

\Drupal\search_api_autocomplete\Suggestion\SuggestionInterface[] An array of suggestions.

1 call to SearchApiSolrBackend::getAutocompleteSuggesterSuggestions()
SearchApiSolrBackend::getSuggesterSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 3661

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function getAutocompleteSuggesterSuggestions(ResultInterface $result, SuggestionFactory $suggestion_factory) {
  $suggestions = [];
  if ($phrases_result = $result
    ->getComponent(ComponentAwareQueryInterface::COMPONENT_SUGGESTER)) {
    foreach ($phrases_result
      ->getAll() as $phrases) {

      /** @var \Solarium\QueryType\Suggester\Result\Term $phrases */
      foreach ($phrases
        ->getSuggestions() as $phrase) {
        $suggestions[] = $suggestion_factory
          ->createFromSuggestedKeys($phrase['term']);
      }
    }
  }
  return $suggestions;
}