- Issue created by @norbert-goco
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
In the schema settings, the Sort option must be enabled for more than three fields.
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.
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);
Active
1.0
Code