You are here

function SearchApiSpellcheckSolr::__construct in Search API Solr 7

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

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

Class

SearchApiSpellcheckSolr
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->spellcheck->suggestions)) {
    $suggestions = $response->spellcheck->suggestions;
    foreach ($suggestions as $word => $data) {
      if (isset($data->suggestion)) {
        foreach ($data->suggestion as $suggestion) {
          $this
            ->addSuggestion(new SearchApiSpellcheckSuggestion($word, $suggestion));
        }
      }
    }
  }
}