You are here

protected function AbstractSearchApiSolrMultilingualBackend::setAutocompleteSuggesterQuery in Search API Solr 8.2

Set the suggester parameters for the solarium autocomplete query.

Parameters

\Drupal\search_api\Query\QueryInterface $query: A query representing the completed user input so far.

AutocompleteQuery $solarium_query: An autocomplete solarium query.

string $user_input: The user input.

array $options: 'dictionary' as string, 'context_filter_tags' as array of strings.

Overrides SearchApiSolrBackend::setAutocompleteSuggesterQuery

File

src/Plugin/search_api/backend/AbstractSearchApiSolrMultilingualBackend.php, line 626

Class

AbstractSearchApiSolrMultilingualBackend
A abstract base class for all multilingual Solr Search API backends.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function setAutocompleteSuggesterQuery(QueryInterface $query, AutocompleteQuery $solarium_query, $user_input, $options = []) {
  if (isset($options['context_filter_tags']) && in_array('drupal/langcode:multilingual', $options['context_filter_tags'])) {
    $langcodes = $query
      ->getLanguages();
    if (count($langcodes) == 1) {
      $langcode = reset($langcodes);
      $options['context_filter_tags'] = str_replace('drupal/langcode:multilingual', 'drupal/langcode:' . $langcode, $options['context_filter_tags']);
      $options['dictionary'] = $langcode;
    }
    else {
      foreach ($options['context_filter_tags'] as $key => $tag) {
        if ('drupal/langcode:multilingual' == $tag) {
          unset($options['context_filter_tags'][$key]);
          break;
        }
      }
    }
  }
  parent::setAutocompleteSuggesterQuery($query, $solarium_query, $user_input, $options);
}