Numbering results based on index

I’ve got an index of over 7000 items that Algolia ranks based on a given field. I’d like to display a ranking number per item, but not have that number change based on the search. (i.e. the 50th item in the index will always show “50” even if it displays as the first result in search). Any ideas how to do that?

I know I could upload the ranking number as a field and use that, but I don’t want to add that extra overhead, since Algolia is already ranking them correctly. (Not to mention that it requires extra updating).

Two other things I can break out into a separate message if preferred:

  • Is there a way to expose a different method of ranking to the user? (i.e. using a different field for ranking, and, as per above, use a new set of display numbers)
  • I’m also hoping to limit the total displayed results for this index to only 100 (out of 7000). Is there a way to set that without deleting a bunch of the index?

Thanks!

Hi @robh,

Thanks for contacting Algolia!

You’ve got a few questions so let’s tackle them one-by-one.

I’d like to display a ranking number per item, but not have that number change based on the search. (i.e. the 50th item in the index will always show “50” even if it displays as the first result in search). Any ideas how to do that?

Because Algolia was designed for dynamic as-you-type results, the static position in the index is not a piece of data returned in the hit information. The solution would be to determine that static position based on some hard sort/calculation in your database, and then add it as a new attribute (as you mentioned).

Is there a way to expose a different method of ranking to the user? (i.e. using a different field for ranking, and, as per above, use a new set of display numbers)

You might be interested in replicas. A replica index has the same data, but pre-sorted by an attribute. Common applications are for price ascending/descending, date ascending/descending. You’ll need to account for the operations and records amount in your plan.

Read more here:

I’m also hoping to limit the total displayed results for this index to only 100 (out of 7000). Is there a way to set that without deleting a bunch of the index?

You can leverage hitsPerPage and set it to 100. Then, provide no pagination, therefore you return 100 and the user cannot request any more hits.

Hope this helps!

Thanks for the response!

Because Algolia was designed for dynamic as-you-type results, the static position in the index is not a piece of data returned in the hit information. The solution would be to determine that static position based on some hard sort/calculation in your database, and then add it as a new attribute (as you mentioned).

The challenge we have here is that we’re providing the data that Algolia then ranks. Basically what you’ve described is that we’ll have to rank it first in our own database, add a field with that information, and send it back to Algolia (to rank again) to display for search. Is that correct?

You might be interested in replicas. A replica index has the same data, but pre-sorted by an attribute.

We’re actually using a replica, but that doesn’t help us surface the ranking change to users of the search. Do we have to embed two separate instant search options and our own toggle to switch between rankings?

You can leverage hitsPerPage and set it to 100. Then, provide no pagination, therefore you return 100 and the user cannot request any more hits.

I don’t think we were planning on displaying all 100 at once, but that still might be doable. That is quite a long list!