You are here

public function SearchApiElasticsearchElastica::parseSearchResponse in Search API Elasticsearch 7

Helper function which parse facets in search().

2 calls to SearchApiElasticsearchElastica::parseSearchResponse()
SearchApiElasticsearchElastica::search in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Overrides search().
SearchApiElasticsearchElastica::searchMultiple in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Implements SearchApiMultiServiceInterface::searchMultiple().

File

modules/elastica/includes/SearchApiElasticsearchElastica.inc, line 785
Provides Elastica client for Search API Elasticsearch.

Class

SearchApiElasticsearchElastica
Search API Elasticsearch Elastica service class.

Code

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

  // Parse results.
  foreach ($response
    ->getResults() as $result) {
    $id = $result
      ->getId();
    $search_result['results'][$id] = array(
      'id' => $id,
      'score' => $result
        ->getScore(),
      'fields' => $result
        ->getSource(),
    );
  }

  // Parse facets.
  $search_result['search_api_facets'] = $this
    ->parseSearchAggregation($response, $query);
  if (module_exists('search_api_spellcheck')) {
    $search_result['search_api_spellcheck'] = new SearchApiElasticsearchElasticaSpellcheck($response);
  }
  return $search_result;
}