You are here

spellcheck.inc in Elasticsearch Connector 7.2

Contains the SearchApiSpellcheckSolr class.

File

modules/elasticsearch_connector_search_api/includes/spellcheck.inc
View source
<?php

/**
 * @file
 * Contains the SearchApiSpellcheckSolr class.
 */

/**
 * Spellcheck class which can provide spelling suggestions. The constructor
 * populates the instance with any suggestions returned by Solr.
 */
class SearchApiSpellcheckElasticsearch extends SearchApiSpellcheck {

  /**
   * Constructs a SearchApiSpellcheckSolr object.
   *
   * If Solr has returned spelling suggestion then loop through them and add
   * them to this spellcheck service.
   *
   * @param object $response
   *   The Solr response object.
   */
  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']));
          }
        }
      }
    }
  }

}

Classes

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