You are here

class Terms in Search API Solr 4.x

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

Provides a suggester that retrieves suggestions from Solr's Terms component.

Plugin annotation


@SearchApiAutocompleteSuggester(
  id = "search_api_solr_terms",
  label = @Translation("Solr Terms"),
  description = @Translation("Autocomplete the entered string based on Solr's Terms component. Note: Be careful when activating this feature if you run multiple indexes in one Solr core! The Terms component is not able to distinguish between the different indexes and returns matching terms for the complete core. If you run multiple indexes in one core the term counts are not correct and you might get suggestions that lead to zero results on a specific index! You can mitigate that effect if you ensure that the fulltext field names are completely different in the indexes.")
)

Hierarchy

  • class \Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester\Terms extends \Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\suggester\Server uses BackendTrait

Expanded class hierarchy of Terms

File

src/Plugin/search_api_autocomplete/suggester/Terms.php, line 17

Namespace

Drupal\search_api_solr\Plugin\search_api_autocomplete\suggester
View source
class Terms extends Server {
  use BackendTrait;

  /**
   * {@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 [];
    }
    if ($this->configuration['fields']) {
      $query
        ->setFulltextFields($this->configuration['fields']);
    }
    else {
      $query
        ->setFulltextFields($query
        ->getIndex()
        ->getFulltextFields());
    }
    return $backend
      ->getAutocompleteSuggestions($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.
Terms::getAutocompleteSuggestions public function