Ability to use multiple fields in range widget
See original GitHub issueWe are implementing an instantsearch on our wocommerce site, and in our scenario we store prices in many fields (ie. depending on current user group - they will receive a certain discount, ie.:
{
id: 123,
title: "apple ipad 32gb black",
price: 200,
price_groupA: 180,
price_groupB: 160,
price_groupC: 150
}
We basically want to be able to generate the request with the OR condition on all price fields that are relevant to currently logged in user.
current range widget is based solely on 1 price “field” and I don’t seem to be able to find anything for query override, ie. current query would translate to something like:
SELECT * FROM products WHERE price BETWEEN 50 AND 100
But i’d like to be able to re-construct that query before it is sent to algolia to convert to something like:
SELECT * FROM products WHERE price BETWEEN 50 AND 100 OR price_groupA BETWEEN 50 AND 100 OR price_groupC BETWEEN 50 AND 100
Example that I showed nearly doesn’t make any sense, but I was trying to make it a little more clear. Real reason is that our user can be member of multiple user groups at the same time, and we want to provide best possible price based on their user group - price associations.
Is this even a right approach? if it is - how can we achieve this type of behaviour, and if it’s not - is there something that anyone could recommend to solve this problem?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (10 by maintainers)
Top GitHub Comments
The use-case seems to make sense. I still have trouble correctly figuring out in my head how a “sort by price” ordering of the results will look, when filtering with on multiple price attributes.
Also, wouldn’t it be possible achieve the same effect by adding new attributes to the records? Like
price_min
andprice_max
being the min and max values of all theprice
,price_groupA
,price_groupB
andprice_groupC
, and we do the filtering on those values. Granted, we would need to compute these min/max for all possible combination of groups, which will quickly be cumbersome.Overall I think it makes sense to integrate it in instantsearch (even if I’m not sure how to do it), but it will require some real-life testing to make sure it solves more issue than it creates (surprising results).
My 2cts 😃
Closing this issue, guidance on achieving this using a custom widget has been provided.