You are here

function SearchApiSpellcheckElasticsearch::__construct in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 modules/elasticsearch_connector_search_api/includes/spellcheck.inc \SearchApiSpellcheckElasticsearch::__construct()
  2. 7.2 modules/elasticsearch_connector_search_api/includes/spellcheck.inc \SearchApiSpellcheckElasticsearch::__construct()

Constructs a SearchApiSpellcheckSolr object.

If Solr has returned spelling suggestion then loop through them and add them to this spellcheck service.

Parameters

object $response: The Solr response object.

File

modules/elasticsearch_connector_search_api/includes/spellcheck.inc, line 22
Contains the SearchApiSpellcheckSolr class.

Class

SearchApiSpellcheckElasticsearch
Spellcheck class which can provide spelling suggestions. The constructor populates the instance with any suggestions returned by Solr.

Code

function __construct($response) {
  if (isset($response['suggest'])) {
    $suggestions = $response['suggest'];
    foreach ($suggestions as $suggestion_name => $data) {
      foreach ($data as $suggestion) {
        foreach ($suggestion['options'] as $option) {
          $this
            ->addSuggestion(new SearchApiSpellcheckSuggestion($suggestion['text'], $option['text']));
        }
      }
    }
  }
}