Use searchable attributes for filtering/sorting but hide from user

My use case is that I want to be able to search through a list of objects and sort them by an attribute that determines importance, but without exposing that exact attribute to the user.

say for instance I have a list of upcoming events and I want the events that have the most participants to have more relevance and thus come up first in the search results. However, I don’t want to show exactly how many participants are in this event. right now all of that is exposed in the network reply in each of the hits that occur. However, I still want to be able to use the field to do sorting for algolia’s response.

I’m using just the front end side of algolia in react. I could make the request from my backend and filter the response to send it to my front end but I would prefer to avoid the extra round trip. I see that you can filter fields from the response from reading the docs but I don’t see a way to specifically filter fields from the hits.

Hi @dliu,

IF you have an event object that looks like this:

{
    "name": "my event",
    "participants": 125
}

You can index those to Algolia. Then in Algolia you can use:

  • Custom Ranking on desc(participants) to list events from most to least participants, after accounting for textual relevance
  • attributesToRetrieve and exclude participants. In this way, participants is used for relevance but not delivered to the frontend

tysm, dunno how I missed that in the docs

1 Like