Facet by Price Ranges?

I’m wondering if it’s possible to use Algolia to do price range facets? I know you can filter by a price range for example, but I’d like to facet by price ranges.

For example I’d like to have facets such as
1-100
100-200 etc… and have only ranges that have products for the given query.

Do i actually have to make those facets in Algolia (name: PriceRange, value: “1-100”) for example, or can I just pivot off of price and dynamically create buckets via query?

Hello Josh :wave:

You can indeed use Algolia to model price ranges on your items!

If you’re using InstantSearch.js on your front-end there’s already a widget which dynamically generates the ranges for you given a numerical price attribute:

image

Alternatively, as you already said, you can define the facet ranges at indexing time: the main difference will be that your facet filter will be much simpler (e.g. instead of price >= 80 AND price <=100 you’ll have price_range:80-100).

Here’s a link to the InstantSearch priceRanges widget:

And here’s a complete demo you can play with:

https://preview.algolia.com/instantsearch/?q=a&idx=instant_search&p=0

Let me know if this helps you out.

Cheers!

Interesting, I didn’t see that before (I’ve been mostly looking at Vue widgets). I’ll take a look!

1 Like