Created on 27 May 2025, about 1 month ago

Problem/Motivation

When the Sort option is enabled for more than three fields, we receive the following error:

Only upto 3 sort fields are allowed.

https://typesense.org/docs/28.0/api/search.html#ranking-and-sorting-para...

Up to 3 sort fields can be specified in a single search query, and they'll be used as a tie-breaker

Steps to reproduce

In the schema settings, the Sort option must be enabled for more than three fields.

Proposed resolution

In the TypesenseClient::getFieldsForSortBy() function, it should be limited to returning a maximum of three fields, and ideally, these should be ranked based on their weight.
The try-catch block is unnecessary in this function.

Remaining tasks

Create a patch:

  $filteredFields = \array_filter($fields, static fn($field): bool => isset($field['index'], $field['sort']) && $field['index'] && $field['sort']);

    // Sort by 'weight' in ascending order.
    usort($filteredFields, static fn($a, $b): int => $a['weight'] <=> $b['weight']);

    $sort_by_fields = \array_map(static fn($field): string => $field['name'] . ':' . $field['sort_type'], $filteredFields);

    // Only upto 3 sort fields are allowed.
    return array_slice($sort_by_fields, 0, 3);
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇷🇸Serbia norbert-goco Subotica

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

Comments & Activities

Production build 0.71.5 2024