By default, Meilisearch sorts results according to their relevancy. You can alter this behavior so users can decide at search time results they want to see first.
sortableAttributes
index settingá
, which has a value of 225, will be sorted after z
, which has a value of 122.Uppercase letters are sorted as if they were lowercase. They will still appear uppercase in search results.sortableAttributes
sortableAttributes
index setting.
author
and price
:
"sort"
is in fifth place. This means it acts as a tie-breaker rule: Meilisearch will first place results closely matching search terms at the top of the returned documents list and only then will apply the "sort"
parameters as requested by the user. In other words, by default Meilisearch provides a very relevant sorting.
Placing "sort"
ranking rule higher in the list will emphasize exhaustive sorting over relevant sorting: your results will more closely follow the sorting order your user chose, but will not be as relevant.
sort
much higher in the ranking rules:
sortableAttributes
, you can use the sort
search parameter to control the sorting order of your search results.
sort
expects a list of attributes that have been added to the sortableAttributes
list.
Attributes must be given as attribute:sorting_order
. In other words, each attribute must be followed by a colon (:
) and a sorting order: either ascending (asc
) or descending (desc
).
When using the POST
route, sort
expects an array of strings:
GET
route, sort
expects a comma-separated string:
sort
values matter: the higher an attribute is in the search parameter value, the more Meilisearch will prioritize it over attributes placed lower. In our example, if multiple documents have the same value for price
, Meilisearch will decide the order between these similarly-priced documents based on their author
.
"science fiction"
books sorted from cheapest to most expensive:
sort
can help grouping results from the same author. This query would only return books matching the query term "butler"
and group results according to their authors: