- Lets users identify items for potential repurchase or review
- Prevents accidental repurchases by reminding users of previous purchases
- Guides users to related or updated versions of products they’ve bought before
- Potentially increases customer loyalty and repeat purchases
This feature isn’t available on every plan.
Refer to your pricing plan to see if it’s included.
Before you begin
This guide assumes that you’re familiar with React InstantSearch and that you have access to user purchase history data.Preview

Storefront displaying labeled purchased items in search results
Provide purchase history data
Start with the purchase history as an array of objects, ordered by purchase date in descending order:JavaScript
objectID,
the unique identifier used in your Algolia index for each product.
Pass this data to the search component:
React
Display a badge for purchased items
To display a badge for purchased items, modify the search results by adding a custom attribute to each hit. This information allows to label items in your search results. Create aSearchPage component that handles the InstantSearch setup:
React
- Creates a lookup object (
purchaseDateByObjectID) for quick access to purchase dates. - Uses the
transformItemsprop of theHitscomponent to add a custom__lastPurchasedAtattribute to each hit. - Specifies a custom
Hitcomponent to render each search result.
Hit component to display the badge:
React
HitPurchasedBadge component:
- Checks if the item has been purchased (has a
__lastPurchasedAtvalue). - If purchased, it formats the date and displays the “Purchased” badge.
- If not purchased, it renders nothing.
Optional: re-rank results based on purchase date
To prioritize purchased items in the search results, you can implement a custom sorting function. This step can enhance the user experience by bringing previously purchased items to the top of the results. Implement a custom sorting function:JavaScript
SearchPage component to use this sorting function:
React