You are here

public function SearchApiSolrBackend::getSpellcheckSuggestions 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::getSpellcheckSuggestions()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getSpellcheckSuggestions()

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides SolrAutocompleteInterface::getSpellcheckSuggestions

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

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

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

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