Cannot apply multiple sorts on query in-code

Created on 28 February 2024, 10 months ago
Updated 29 February 2024, 10 months ago

Problem/Motivation

I am trying to add multiple sort conditions in hook_search_api_query_alter() but using the sort() method allows only one field, and if you reuse it it overrides the previous one.

Proposed resolution

Add a setSorts() method to Search API's Query.php accepting an array of fields to sort by.

I am not entirely sure if this a correct approach for the issue, but it worked for me so maybe it would be helpful.
It will need checking in a query alter for an order parameter in order to avoid this overriding your exposed or table sorting.

🐛 Bug report
Status

Closed: works as designed

Version

1.31

Component

General code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024