You are here

public function SearchApiElasticsearchConnector::search in Elasticsearch Connector 7

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::search()
  2. 7.2 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::search()

Overrides search().

Overrides SearchApiServiceInterface::search

1 call to SearchApiElasticsearchConnector::search()
SearchApiElasticsearchConnector::getAutocompleteSuggestions in modules/elasticsearch_connector_search_api/service.inc
Implements SearchApiAutocompleteInterface::getAutocompleteSuggestions().

File

modules/elasticsearch_connector_search_api/service.inc, line 578
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service class.

Code

public function search(SearchApiQueryInterface $query, $suggestions = FALSE) {

  // Results.
  $search_result = array(
    'result count' => 0,
  );

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

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

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

  // Add facets.
  $this
    ->addSearchFacets($params, $query);
  $this
    ->buildAdditionalProcessorQuery($params, $query);

  // Alter the query and params.
  drupal_alter('elasticsearch_connector_search_api_query', $query, $params);
  try {

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

    // TODO: Fix the logging to be accurate!
    if (!empty($index->options['collect_index_statistics']) && !$suggestions && class_exists('SearchApiElasticsearchConnectorStats')) {
      $stats = new SearchApiElasticsearchConnectorStats($query, $this);
      $stats
        ->logStat($response);
    }

    // Parse response.
    $results = $this
      ->parseSearchResponse($response, $query);
    drupal_alter('elasticsearch_connector_search_api_results', $results, $query, $response);
  } catch (Exception $e) {
    watchdog('Elasticsearch Search API', check_plain($e
      ->getMessage()), array(), WATCHDOG_ERROR);
    return array(
      'result count' => 0,
    );
  }
  return $results;
}