Allow multiple sort fields

Created on 9 May 2025, about 20 hours ago

Problem/Motivation

I would like to be able to sort search results by two fields. In my case, sorting by date (descending) and by title (ascending). Currently, the configuration options for an endpoint allow only one sorting field and one sorting order. Also, I have examined the prepareQuery function in the SearchApiEndpointController and it does not appear possible to provide a query parameter with the endpoint url indicating more than one sort field (like "&sort=date,title").

Proposed resolution

As a test, I added a hard-coded secondary sort in prepareQuery function (right below the existing sort declaration on line 225 of SearchApiEndpointController):

<pre>$query->sort($sort, $order); // existing line of code
$query->sort('title', 'asc');</pre>

This had the desired effect. My search results were sorted both by the default sort (date) and then the additional sort (title).

My suggestion is twofold:

  1. Update the prepareQuery function so that it could recognize and accept a comma-delimited string for the 'sort' parameter and the 'order' parameter
  2. Update the SearchApiEndpointForm in some way to allow adding multiple sort/order pairs

These changes might necessitate additional modifications elsewhere.

Data model changes

I'm not sure if there are data model changes. It might be necessary to store the default sort and order values in a different way so as to maintain the sort/order pairs.

✨ Feature request
Status

Active

Version

1.0

Component

Endpoint

Created by

πŸ‡ΊπŸ‡ΈUnited States aaronpinero

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

Comments & Activities

Production build 0.71.5 2024