Forcing a sort order by ID field using instantsearch

instantsearch
sorting
#1

Hi, we’re using InstantSearch and have a specific feature where we are storing in our DB a set of IDs (of our “thing” that we’re indexing in Algolia). We allow our user to set the ordeting of those IDs (with a sort order that we’re managing in our DB).

Now, when the user selects that saved list, we construct a URL to pass into instantsearch the id parameter and all the values in the order which they’re stored in our DB. Example:

/listings?id=168~662~170~746~664~667~675~676~766~765

We’d like the search results to actually be in that order - 168, then 662, then 170, etc.

BUT, It’s actualy being returned according to our index’s sort settings.

Is there a way to state that if I want it to be sorted in the ordering of the IDs I pass into the ID parameter?

Thanks
Chris

#2

Hi @marketplace-tech,

Thanks for contacting Algolia.

Indeed, as you stated, "It’s actualy being returned according to our index’s sort settings." - Algolia is working correctly as it is returning results to you based on the relevance settings you configured.

If you would like this ordering which is based on your DB, this will have to be handled after the hits are returned from Algolia, and you’l do this manually on the frontend.

For example, I expect the flow will be something akin to:

  • Trigger Algolia search
  • Collect hits
  • Retrieve this ID list from your DB
  • Filter through hits and put in order based on the data from your DB

This would be outside the scope of Algolia, and more of a frontend development feature. Does that make sense?

Let us know how it goes.

#3

Hi, yep makes sense. thanks for the explanation., Will discuss with the team!