Reputation: 1075
I have an index of thousands of music tracks. For searching I want the tracks to be returned by track title ascending.
I also have the created_at
field which is a date time of when I added the track to library. Is it ok for me to change the ranking on the fly?
So for my normal artist / title search before the query I would run:
index.setSettings({
ranking: [
"asc(title)",
"asc(artist)"
]
});
And then when I want to return the tracks I recently added to the database I would run:
index.setSettings({
ranking: [
"desc(created_at)",
"asc(title)",
"asc(artist)"
]
});
My question is: Is this performant? Are there any down sides for doing this for each query?
Thanks for the advice!
Upvotes: 3
Views: 1085
Reputation: 1193
Algolia sort data at indexing time, not query time. That's why you have to use the method setSettings
. If you do it this way, all the data will be resorted every time you set the new settings.
The solution is to use replicas. They are a copy of the master index, sorted differently.
You can find the relevant doc here: https://www.algolia.com/doc/guides/relevance/sorting/#multiple-sorting-strategies
Upvotes: 3