public function SearchApiElasticsearchElastica::search in Search API Elasticsearch 7
Overrides search().
Overrides SearchApiServiceInterface::search
File
- modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc, line 321 - Provides Elastica client for Search API Elasticsearch.
Class
- SearchApiElasticsearchElastica
- Search API Elasticsearch Elastica service class.
Code
public function search(SearchApiQueryInterface $query) {
// Results.
$search_result = array(
'result count' => 0,
);
// Get index.
$index = $query
->getIndex();
// Get index type.
$elastica_type = $this
->getElasticaType($index);
// Get query options.
$query_options = $this
->getSearchQueryOptions($query);
// Check elasticsearch index.
if (empty($elastica_type)) {
return $search_result;
}
// Build Elastica query.
$elastica_query = $this
->buildSearchQuery($query);
// Add facets.
$this
->addSearchAggregation($elastica_query, $query);
$response = SearchApiElasticsearchElasticaSearcher::search($elastica_type, $elastica_query, $query_options, $query);
// Show Elasticsearch query string from Elastica
// as json output when views debug output is enabled.
if (function_exists('vpr') && ($elastica_param_query = $elastica_query
->getParam('query'))) {
vpr(drupal_json_encode($elastica_param_query));
}
// Parse response.
return $this
->parseSearchResponse($response, $query);
}