You are here

public function QueryInterface::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 ID of the field to sort by. In addition to all indexed fields on the index, the following special field IDs may be used:

  • search_api_relevance: Sort by relevance.
  • search_api_datasource: Sort by datasource.
  • search_api_language: Sort by language.
  • search_api_id: Sort by item ID.

string $order: The order to sort items in – one of the SORT_* constants.

Return value

$this

See also

\Drupal\search_api\Query\QueryInterface::SORT_ASC

\Drupal\search_api\Query\QueryInterface::SORT_DESC

1 method overrides QueryInterface::sort()
Query::sort in src/Query/Query.php
Adds a sort directive to this search query.

File

src/Query/QueryInterface.php, line 216

Class

QueryInterface
Represents a search query on a Search API index.

Namespace

Drupal\search_api\Query

Code

public function sort($field, $order = self::SORT_ASC);