You are here

public function SearchApiElasticsearchConnector::parseSearchResponse in Elasticsearch Connector 7

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

Helper function which parse facets in search().

1 call to SearchApiElasticsearchConnector::parseSearchResponse()
SearchApiElasticsearchConnector::search in modules/elasticsearch_connector_search_api/service.inc
Overrides search().

File

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

Class

SearchApiElasticsearchConnector
Search service class.

Code

public function parseSearchResponse($response, SearchApiQueryInterface $query) {
  $search_result = array(
    'results' => array(),
  );
  $search_result['result count'] = $response['hits']['total'];

  // Parse results.
  if (!empty($response['hits']['hits'])) {
    foreach ($response['hits']['hits'] as $result) {
      $id = $result['_id'];
      $search_result['results'][$id] = array(
        'id' => $result['_id'],
        'score' => $result['_score'],
        'fields' => isset($result['_source']) ? $result['_source'] : array(),
      );
      foreach ($result as $key => $value) {
        if (!in_array($key, array(
          '_id',
          '_score',
          '_source',
        ))) {
          $search_result['results'][$id][$key] = $value;
        }
      }
    }
  }
  $search_result['search_api_facets'] = $this
    ->parseSearchFacets($response, $query);

  // Check for spellcheck suggestions.
  if (module_exists('search_api_spellcheck') && $query
    ->getOption('search_api_spellcheck')) {
    $search_result['search_api_spellcheck'] = new SearchApiSpellcheckElasticsearch($response);
  }
  return $search_result;
}