meilisearch-js-plugins
meilisearch-js-plugins copied to clipboard
SortBy should allow for multiple sort attributes at query time
Description SortBy should allow for multiple sort attributes at query time.
Basic example
instantsearch.widgets.sortBy({
container: '#sort-by',
items: [
{ value: 'clothes', label: 'Relevant' }, // default index
{
value: 'clothes:price:asc,created_at:desc',
label: 'Ascending price then descending creation time using query time sort',
},
],
}),
This sort formula is probably not ideal for parsing, it is just an example.
Thats a good idea. Yes, unfortunately, we are bound to the props instantSearch provides. I don't really see a better way of delimiting the multiple options. A split on ,
should do the trick. The question is, what happens when a field contains commas, and, should we care?
The user (developer) has control over these strings, whatever delimiter is chosen can be escaped by the user in the tag names. The parser could then process escape sequences before splitting.
As you mentioned, worrying about this may not be worth it, at least at this stage.
So the implementation would be to split the different sorting queries with commas, and then populate the sort query parameter with all the sorting requests.
- [ ] implement multiple sorting
- [ ] Add tests
- [ ] Update docs