React instantsearch and optional filters to rank a list of object ids first in search results

Hello,
I have a personalization use case where I need to rank a list of object ids first on initial page load. The object ids are produced server side by a separate system. My first thought was to use optionalFilters with a list of object ids ['objectId:1', 'objectId:2', ...].

But if you’re on an essential plan Algolia only allows “1 optionalFilters per query” which I guess does not include multiple values for the same attribute? [https://www.algolia.com/doc/api-reference/api-parameters/optionalFilters/](relevant documentation).

I suppose I could fetch the objects by id on initial page load and insert them into my results using a custom Hits component, but I wonder if there is a way to achieve this using optionalFilters or another method.

Thanks for any help.

Hi @ericwconner,

Thanks for contacting Algolia!

You’ve actually hit the suggestion I would have provided. Indeed, optionalFilters are helpful, but your use case would require more than one optional filter.

In your situation, I would recommend the multiple-queries approach you described:

  • Send one query to retrieve your desired results by objectID.
  • Send a second query for the remaining/normal query, filtering out any hits that pertain to objectIDs in the first set.

As you also mentioned, you would have to handle and display the hits yourself on the front-end.

I hope this affirmation of your thought process keeps you moving forward!

Best regards,

Thanks Ajay! I did follow through with this approach and it’s functional though a little slower than I’d like. Would love to be able to use multiple optional filters on an Essential plan :grinning:. Maybe someday.