You are here

class Spellcheck in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api_autocomplete/suggester/Spellcheck.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Spellcheck
  2. 8.2 src/Plugin/search_api_autocomplete/suggester/Spellcheck.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Spellcheck

Provides a suggester plugin that retrieves suggestions from the server.

The server needs to support the "search_api_autocomplete" feature for this to work.

Plugin annotation


@SearchApiAutocompleteSuggester(
  id = "search_api_solr_spellcheck",
  label = @Translation("Solr Spellcheck"),
  description = @Translation("Suggest corrections for the entered words based on Solr's spellcheck component. Note: Be careful when activating this feature if you run multiple indexes in one Solr core! The spellcheck component is not able to distinguish between the different indexes and returns suggestions for the complete core. If you run multiple indexes in one core you might get suggestions that lead to zero results on a specific index!"),
)

Hierarchy

  • class \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Spellcheck extends \Drupal\search_api_autocomplete\Suggester\SuggesterPluginBase implements PluginFormInterface uses \Drupal\search_api\Plugin\PluginFormTrait, BackendTrait

Expanded class hierarchy of Spellcheck

1 string reference to 'Spellcheck'
search_api_solr.solr_request_handler.request_handler_spell_default_7_0_0.yml in config/install/search_api_solr.solr_request_handler.request_handler_spell_default_7_0_0.yml
config/install/search_api_solr.solr_request_handler.request_handler_spell_default_7_0_0.yml

File

src/Plugin/search_api_autocomplete/suggester/Spellcheck.php, line 24

Namespace

Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester
View source
class Spellcheck extends SuggesterPluginBase implements PluginFormInterface {
  use PluginFormTrait;
  use BackendTrait;

  /**
   * {@inheritdoc}
   *
   * @throws \Drupal\search_api\SearchApiException
   * @throws \Drupal\search_api_autocomplete\SearchApiAutocompleteException
   */
  public static function supportsSearch(SearchInterface $search) {

    /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
    $backend = static::getBackend($search
      ->getIndex());
    return $backend && version_compare($backend
      ->getSolrConnector()
      ->getSolrMajorVersion(), '4', '>=');
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return [];
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Drupal\search_api\SearchApiException
   * @throws \Drupal\search_api_autocomplete\SearchApiAutocompleteException
   */
  public function getAutocompleteSuggestions(QueryInterface $query, $incomplete_key, $user_input) {
    if (!($backend = static::getBackend($this
      ->getSearch()
      ->getIndex()))) {
      return [];
    }
    return $backend
      ->getSpellcheckSuggestions($query, $this
      ->getSearch(), $incomplete_key, $user_input);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BackendTrait::getBackend protected static function Retrieves the backend for the given index, if it supports autocomplete.
PluginFormInterface::submitConfigurationForm public function Form submission handler. 32
PluginFormInterface::validateConfigurationForm public function Form validation handler. 18
Spellcheck::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
Spellcheck::defaultConfiguration public function
Spellcheck::getAutocompleteSuggestions public function
Spellcheck::supportsSearch public static function