You are here

public function SearchApiSolrBackend::getAutocompleteSuggestions in Search API Solr 8.2

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::getAutocompleteSuggestions()
  2. 8 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.

See also

\Drupal\search_api_autocomplete\AutocompleteBackendInterface

1 call to SearchApiSolrBackend::getAutocompleteSuggestions()
SearchApiSolrBackend::getTermsSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Autocompletion suggestions for some user input using Terms component.

File

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

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) {

  // For example, let the multilingual backend set the correct fields.
  $this
    ->alterSearchApiQuery($query);
  $suggestions = [];
  if ($solarium_query = $this
    ->getAutocompleteQuery($incomplete_key, $user_input)) {
    try {
      $suggestion_factory = new SuggestionFactory($user_input);
      $this
        ->setAutocompleteTermQuery($query, $solarium_query, $incomplete_key);
      $result = $this
        ->getSolrConnector()
        ->execute($solarium_query);
      $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;
}