You are here

public function SearchApiSolrBackend::getAutocompleteSuggestions in Search API Solr 8.3

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

Implements autocomplete compatible to AutocompleteBackendInterface.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

See also

\Drupal\search_api_autocomplete\AutocompleteBackendInterface

1 call to SearchApiSolrBackend::getAutocompleteSuggestions()
SearchApiSolrBackend::getTermsSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function getAutocompleteSuggestions(QueryInterface $query, $search, $incomplete_key, $user_input) {
  $suggestions = [];
  if ($solarium_query = $this
    ->getAutocompleteQuery($incomplete_key, $user_input)) {
    try {
      $suggestion_factory = new SuggestionFactory($user_input);
      $this
        ->ensureLanguageCondition($query);
      $this
        ->setAutocompleteTermQuery($query, $solarium_query, $incomplete_key);
      $result = $this
        ->getSolrConnector()
        ->execute($solarium_query, $this
        ->getCollectionEndpoint($query
        ->getIndex()));
      $suggestions = $this
        ->getAutocompleteTermSuggestions($result, $suggestion_factory, $incomplete_key);

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