priceRange Filter with Values in different currencies

Hi there, I’m not sure if this is even the correct title for what I want, but I’ll explain what I need and if you guys could please let me know if is possible to do this and if so how to do it.

My Algolia records have a specific attribute for name price, and also have a currency field. So for example, I have records like this.

{
    name: "Product A",
    price: 200,
    currency: "USD"
},
{
    name: "Product B",
    price: 150,
    currency: "GBP"
},
{
    name: "Product C",
    price: 250,
    currency: "EUR"
}

And on my website all my prices should be displayed in USD. And for this, I have an array of exchange rates from open exchange rates like this:

{
    disclaimer: "https://openexchangerates.org/terms/",
    license: "https://openexchangerates.org/license/",
    timestamp: 1449877801,
    base: "USD",
    rates: {
        AED: 3.672538,
        AFN: 66.809999,
        ALL: 125.716501,
        AMD: 484.902502,
        ANG: 1.788575,
        AOA: 135.295998,
        ARS: 9.750101,
        AUD: 1.390866
    }
}

I’m able to display the prices in USD on my hits results, but the problem is that I want to implement the priceRange filter for values in USD. Is it possible to do this? To set the ranges and filter by multiplying or dividing by the exchange rate?

Thanks

Hi Gabriel,

I would recommend you index the USD price . You record could be something like

{
name: “Product A”,
price: {
“USD”: 172,
“EUR”: 199
}
}

Then you will be able to use price.USD as a facet filter.

The downside is that you will have to reindex prices regularily.

Does that help?

Hi Julien,
I had thought about this, but the problem is that our exchange rates are daily updated, and sometimes we need to updated the exchange rate more than once a day. We also have plans to sell internationally, so the user should be able to choose what “base” currency does he/she want to buy from.

We also have around 3k records, what makes Inviable to keep updating those records every time the exchange rates change

In this case, I think the best will be to create a custom instantsearch widget. I assume you are using instantsearch.js.

Here is an example of one we made: https://github.com/instantsearch/instantsearch-ion.rangeSlider
What you’ll need is very similar. You can then convert all data easily.