You are here

public function SearchApiSolrBackend::getSuggesterSuggestions in Search API Solr 4.x

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

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides SolrAutocompleteInterface::getSuggesterSuggestions

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function getSuggesterSuggestions(QueryInterface $query, SearchInterface $search, $incomplete_key, $user_input, array $options = []) {
  $suggestions = [];
  if ($solarium_query = $this
    ->getAutocompleteQuery($incomplete_key, $user_input)) {
    try {
      $suggestion_factory = new SuggestionFactory($user_input);
      $this
        ->setAutocompleteSuggesterQuery($query, $solarium_query, $user_input, $options);

      // Allow modules to alter the solarium autocomplete query.
      $this->moduleHandler
        ->alter('search_api_solr_suggester_autocomplete_query', $solarium_query, $query);
      $result = $this
        ->getSolrConnector()
        ->autocomplete($solarium_query, $this
        ->getCollectionEndpoint($query
        ->getIndex()));
      $suggestions = $this
        ->getAutocompleteSuggesterSuggestions($result, $suggestion_factory);

      // Filter out duplicate suggestions.
      $this
        ->filterDuplicateAutocompleteSuggestions($suggestions);
    } catch (SearchApiException $e) {
      watchdog_exception('search_api_solr', $e);
    }
  }
  return $suggestions;
}