protected function SearchApiElasticsearchAbstractService::getSortSearchQuery in Search API Elasticsearch 7
Helper function that return Sort for query in search.
1 call to SearchApiElasticsearchAbstractService::getSortSearchQuery()
- SearchApiElasticsearchElastica::getSearchQueryOptions in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Helper function return associative array with query options.
File
- includes/
SearchApiElasticsearchAbstractService.inc, line 560 - Provides a Elasticsearch-based service class for the Search API.
Class
- SearchApiElasticsearchAbstractService
- Elasticsearch service abstract class.
Code
protected function getSortSearchQuery(SearchApiQueryInterface $query) {
$index_fields = $this
->getIndexFields($query);
$sort = array();
foreach ($query
->getSort() as $field_id => $direction) {
$direction = drupal_strtolower($direction);
if ($field_id === 'search_api_relevance') {
$sort['_score'] = $direction;
}
elseif (isset($index_fields[$field_id])) {
$sort[$field_id] = $direction;
}
else {
throw new Exception(t('Incorrect sorting!.'));
}
}
return $sort;
}