Traversing a search query

Our team has built a small app with Algolia and React that is working great. We want to implement a feature that will allow users to swipe left/right when they are viewing a specific result that will take them to the next/previous result from their last search.

Is there a way to find the previous/next result using the current search result position, and the query ID? Has anyone implemented something similar that might be willing to share their approach to this problem?

Thank you!

Are you only displaying records one at a time in your app? If so, I would handle this through pagination, by setting hitsPerPage to 1 and requesting specific pages:

Alternately, you you could use offset and length to display individual records, but I’d recommend the pagination approach as a starting point.

Thanks for the reply Chuck.

Our site is a repository of 18th century quotes and stories that have been translated to English. We display search results 12 at a time when a user enters a search query. Search results are presented as cards with a title, author name, and category.

When a user clicks a card, they are brought to a page that shows much more information, including the full text of the original text and the english translation. Our users would like a way to quickly traverse from inside one of these entries to the next/previous entry given their previous search.

We have thought of a few ways to maybe handle this, but our ideas feel a bit like a hack. ie: conduct the search again when the user lands on the page, find the index of the current result, see if the previous/next items in the array of results can be retrieved, or paginate up/down to find those results… It seems like we might run into some duplicate queries, and honestly would probably require a lot of restructuring of the app in general.

Maybe something like this is the best approach though. We were sort of hopeful that maybe we could use Query ID to retrieve previous results to somehow optimize the number of queries we were making.

That makes sense. Yeah, the more typical navigation pattern is to send the user back to the results page to click the next record. You could certainly pass along the hits object into the details page to keep the results from the initial query for navigation, but it could get messy if you were going to allow them to continue to navigate across pagination boundaries.

Another approach would be to “pop up” a quick view of the details page as an overlay/sidebar so the user isn’t actually leaving the results and can quickly navigate to another choice.

You could also display similar quotes on the details page based on faceting or attribute values of the index, but that’s drifting away of your original intent

I think we’re going to opt for the messy route for our use case :sweat_smile:. I appreciate the different approaches you provided here, they all seem like they good be good choices.

Thanks again!