Get page number of a hit relative to all objects


Lets say I have 40 objects in my index and inside my web application I show 10 items per page (4 pages in total). When I search for certain objects my hits get limited to the search criteria. So far so good.

However, now I would like to know on what page this object would be if I do not pass any search criteria or if I enter a less specific search criteria that returns more than 10 results.

I am looking for a possible solution to support this somewhat special use case.

Best Regards

Hi @se11,

The only solution will be to make a second query without the search criteria, to figure this out. If you only have 40 objects, it will be fine to request them all at once (use hitsPerPage parameter) and figure out the position.

Can you also share why you’d like to do that? I’m not sure to understand the use case.

Thank you for your quick reply. Actually the 40 objects was just an example. There are actually several thousand of objects.

The actual use case involves a hierarchical structure with 3 levels: Customer -> Locations -> Products. One can now for example search for a certain location and this location belongs to lets say customer A. However, in order to see all locations of that specific customer and the locations products, we allowed the user to double click on the found location, the search criteria gets reset and the view jumps to the page where the locations customer is listed.

I am fully aware that there might a better solution altogether to handle the actual use case (getting all locations from Customer A and to see the locations products). But this is how it has been solved. Right now we solve this with a lot of hand written SQL, but this is as you probably guessed by far not as fast as your search engine and a nightmare to maintain.

That would be a very tough case, I think you will have to query the search endpoint until you find the records. There is no way to know the position otherwise.

Actually, the browse endpoin would be better suited: