You are here

public function SearchApiElasticsearchBackend::search in Elasticsearch Connector 8

Same name and namespace in other branches
  1. 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::search()
  2. 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::search()
  3. 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::search()
  4. 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::search()

Overrides search().

Overrides BackendSpecificInterface::search

1 call to SearchApiElasticsearchBackend::search()
SearchApiElasticsearchBackend::getAutocompleteSuggestions in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Helper function. Get Autocomplete suggestions.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 613
Contains the SearchApiElasticsearchBackend object.

Class

SearchApiElasticsearchBackend
Plugin annotation @SearchApiBackend( id = "elasticsearch", label = @Translation("Elasticsearch"), description = @Translation("Index items using an Elasticsearch server.") )

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

public function search(QueryInterface $query) {

  // Results.
  $search_result = SearchApiUtility::createSearchResultSet($query);

  // Get index
  $index = $query
    ->getIndex();
  $params = $this
    ->getIndexParam($index, TRUE);

  // Check elasticsearch index.
  $this
    ->connect();
  if (!$this->elasticsearchClient
    ->getIndices()
    ->existsType($params)) {
    return $search_result;
  }
  $query
    ->setOption('ElasticParams', $params);

  // Build Elastica query.
  $params = $this
    ->buildSearchQuery($query);

  // Add facets.

  //$this->addSearchFacets($params, $query);

  // Do search.
  $response = $this->elasticsearchClient
    ->search($params);

  // Parse response.
  return $this
    ->parseSearchResponse($response, $query);
}