You are here

protected function SearchApiElasticsearchQuery::getSortQuery in Search API Elasticsearch 7.2

Get sorting configuration.

Return value

array

Throws

Exception

1 call to SearchApiElasticsearchQuery::getSortQuery()
SearchApiElasticsearchQuery::build in includes/SearchApiElasticsearchQuery.inc
Build Elastica query for Elasticsearch.

File

includes/SearchApiElasticsearchQuery.inc, line 528

Class

SearchApiElasticsearchQuery
@file

Code

protected function getSortQuery() {
  $sort = [];
  foreach ($this->search_api_query
    ->getSort() as $field_id => $direction) {
    $direction = drupal_strtolower($direction);
    if ($field_id === 'search_api_relevance') {
      $sort['_score'] = $direction;
    }
    elseif (isset($this->index_fields[$field_id])) {
      $sort[$field_id] = $direction;
    }
    else {
      throw new Exception(t('Incorrect Sorting!'));
    }
  }
  return $sort;
}