You are here

protected static function BackendTrait::getBackend in Search API Solr 4.x

Same name in this branch
  1. 4.x src/Controller/BackendTrait.php \Drupal\search_api_solr\Controller\BackendTrait::getBackend()
  2. 4.x src/Plugin/search_api_autocomplete/suggester/BackendTrait.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\BackendTrait::getBackend()
Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api_autocomplete/suggester/BackendTrait.php \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\BackendTrait::getBackend()

Retrieves the backend for the given index, if it supports autocomplete.

Parameters

\Drupal\search_api\IndexInterface $index: The search index.

Return value

\Drupal\search_api_solr\SolrAutocompleteInterface|null The backend plugin of the index's server, if it exists and supports autocomplete; NULL otherwise.

5 calls to BackendTrait::getBackend()
Spellcheck::getAutocompleteSuggestions in src/Plugin/search_api_autocomplete/suggester/Spellcheck.php
Spellcheck::supportsSearch in src/Plugin/search_api_autocomplete/suggester/Spellcheck.php
Suggester::getAutocompleteSuggestions in src/Plugin/search_api_autocomplete/suggester/Suggester.php
Suggester::supportsSearch in src/Plugin/search_api_autocomplete/suggester/Suggester.php
Terms::getAutocompleteSuggestions in src/Plugin/search_api_autocomplete/suggester/Terms.php

File

src/Plugin/search_api_autocomplete/suggester/BackendTrait.php, line 26

Class

BackendTrait
Provides a helper method for loading the search backend.

Namespace

Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester

Code

protected static function getBackend(IndexInterface $index) {
  try {
    if ($index
      ->hasValidServer() && ($server = $index
      ->getServerInstance()) && ($backend = $server
      ->getBackend()) && $backend instanceof SolrAutocompleteInterface && $server
      ->supportsFeature('search_api_autocomplete')) {
      return $backend;
    }
  } catch (\Exception $e) {
    watchdog_exception('search_api', $e);
  }
  return NULL;
}