You are here

public function SearchApiQuery::sort in Search API 8

Adds a sort directive to this search query.

If no sort is manually set, the results will be sorted descending by relevance.

Parameters

string $field: The field to sort by. The special fields 'search_api_relevance' (sort by relevance) and 'search_api_id' (sort by item id) may be used.

string $order: The order to sort items in - either 'ASC' or 'DESC'.

Return value

$this

See also

\Drupal\search_api\Query\QueryInterface::sort()

1 call to SearchApiQuery::sort()
SearchApiQuery::addOrderBy in src/Plugin/views/query/SearchApiQuery.php
Adds an ORDER BY clause to the query.

File

src/Plugin/views/query/SearchApiQuery.php, line 1245

Class

SearchApiQuery
Defines a Views query class for searching on Search API indexes.

Namespace

Drupal\search_api\Plugin\views\query

Code

public function sort($field, $order = 'ASC') {
  if (!$this
    ->shouldAbort()) {
    $this->query
      ->sort($field, $order);
  }
  return $this;
}