You are here

protected function SearchApiSolrBackend::extractSpellCheckSuggestions in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::extractSpellCheckSuggestions()

Get the spellcheck suggestions from the autocomplete query result.

Parameters

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

Return value

array An array of suggestions.

2 calls to SearchApiSolrBackend::extractSpellCheckSuggestions()
SearchApiSolrBackend::getAutocompleteSpellCheckSuggestions in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Get the spellcheck suggestions from the autocomplete query result.
SearchApiSolrBackend::search in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Options on $query prefixed by 'solr_param_' will be passed natively to Solr as query parameter without the prefix. For example you can set the "Minimum Should Match" parameter 'mm' to '75%' like this:

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

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

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