You are here

public function Suggester::getAutocompleteSuggestions in Search API Solr 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/search_api_autocomplete/suggester/Suggester.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Suggester::getAutocompleteSuggestions()
  2. 4.x src/Plugin/search_api_autocomplete/suggester/Suggester.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Suggester::getAutocompleteSuggestions()

Throws

\Drupal\search_api\SearchApiException

\Drupal\search_api_autocomplete\SearchApiAutocompleteException

Overrides SuggesterInterface::getAutocompleteSuggestions

File

src/Plugin/search_api_autocomplete/suggester/Suggester.php, line 116

Class

Suggester
Provides a suggester plugin that retrieves suggestions from the server.

Namespace

Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester

Code

public function getAutocompleteSuggestions(QueryInterface $query, $incomplete_key, $user_input) {
  if (!($backend = static::getBackend($this
    ->getSearch()
    ->getIndex()))) {
    return [];
  }
  $config = $this
    ->getConfiguration();
  $options['context_filter_tags'] = [];
  if ($config['search_api_solr/site_hash']) {
    $options['context_filter_tags'][] = 'search_api_solr/site_hash:' . Utility::getSiteHash();
  }
  if (!empty($config['search_api/index']) && 'any' !== $config['search_api/index']) {
    $options['context_filter_tags'][] = 'search_api/index:' . $config['search_api/index'];
  }
  if ('any' !== $config['drupal/langcode']) {
    $options['context_filter_tags'][] = 'drupal/langcode:' . $config['drupal/langcode'];
  }
  return $backend
    ->getSuggesterSuggestions($query, $this
    ->getSearch(), $incomplete_key, $user_input, $options);
}