You are here

protected function SearchApiSolrBackend::getAutocompleteSpellCheckSuggestions 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::getAutocompleteSpellCheckSuggestions()
  2. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getAutocompleteSpellCheckSuggestions()

Get the spellcheck suggestions from the autocomplete query result.

Parameters

\Solarium\Core\Query\Result\ResultInterface $result: A autocomplete query result.

\Drupal\search_api_autocomplete\Suggestion\SuggestionFactory $suggestion_factory: The suggestion factory.

Return value

\Drupal\search_api_autocomplete\Suggestion\SuggestionInterface[] An array of suggestions.

1 call to SearchApiSolrBackend::getAutocompleteSpellCheckSuggestions()
SearchApiSolrBackend::getSpellcheckSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Autocompletion suggestions for some user input using Spellcheck component.

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function getAutocompleteSpellCheckSuggestions(ResultInterface $result, SuggestionFactory $suggestion_factory) {
  $suggestions = [];
  if ($spellcheck_results = $result
    ->getComponent(ComponentAwareQueryInterface::COMPONENT_SPELLCHECK)) {
    foreach ($spellcheck_results as $term_result) {

      /** @var \Solarium\Component\Result\Spellcheck\Suggestion $term_result */
      foreach ($term_result
        ->getWords() as $correction) {
        $suggestions[] = $suggestion_factory
          ->createFromSuggestedKeys($correction['word']);
      }
    }
  }
  return $suggestions;
}