You are here

protected function IndexResource::applySortingToQuery in JSON:API Search API 8

Apply sorting to the index query.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

\Drupal\search_api\Query\QueryInterface $query: The query.

\Drupal\Core\Cache\CacheableMetadata $cacheability: The cache metadata.

Throws

\Drupal\Component\Plugin\Exception\PluginException

1 call to IndexResource::applySortingToQuery()
IndexResource::process in src/Resource/IndexResource.php
Process the resource request.

File

src/Resource/IndexResource.php, line 180

Class

IndexResource
JSON:API Resource to return Search API index results.

Namespace

Drupal\jsonapi_search_api\Resource

Code

protected function applySortingToQuery(Request $request, QueryInterface $query, CacheableMetadata $cacheability) : void {
  $sort_params = $request->query
    ->get('sort');
  $sort = Sort::createFromQueryParameter($sort_params);
  foreach ($sort
    ->fields() as $field) {
    $query
      ->sort($field['path'], $field['direction']);
  }
}