Very special filter behavior

Hi all,

I have a very specific requirement in one of my projects. The use case is the following: I have products in my index, which are evaluated by the company and are rated according to the testing’s outcome. The following certification classes exist: 2a, 2b, 2c, 2d, 2e, 3a, 3b, 3c, 3d and 3e (2a being the lowest and 3e being the highest standard). Now the customer would like to have the filter behavior as described below.

If the user chooses for example standard “2c”, it is expected to see all products, which have the classes: 2c, 2d, 2e, 3c, 3d and 3e. Here are some more examples to better understand the logic.

Standard choosen: 2e; Shown products: 2e, 3e
Standard choosen: 3b; Shown products: 3b, 3c, 3d, 3e
Standard choosen: 2b; Shown products: 2b, 2c, 2d, 2e, 3b, 3c, 3d, 3e

Is this kind of behavior possible to achieve with any Instantsearch widget?

Thank you for your help!

Hi @aarongerig, that’s an interesting use case. Would it be possible to add another attribute with numeric values that map to the classifications? If so, then you could use a numeric filter to find those records that match or are ‘greater’ than the entered standard.

In your code, have an array that maps 2a to 1, 2b to 2, etc. Store the numeric values in your record as an attribute, then search with a filter based on the mapped attributes.

Hi @cindy.cullen, thanks for looking into this. Your proposed solution actually was my first thought as well, but unfortunately wouldn’t work out. Let’s go through that really quick.

2a = 1
2b = 2
2c = 3
2d = 4
2e = 5
3a = 6
3b = 7
3c = 8
3d = 9
3e = 10

Now if 2c (3) was active, it would have to show values with 3, 4, 5, 8, 9 and 10. You see, it always has to match the “higher” letters inside the same category (2 or 3) and the same letter in the higher category if it has any. That logic can’t be applied to a series of numbers.

Here’s a visual representation of the filter. The Y axis holds the required classification and the X axis shows, which of the classification fulfills that requirement.

Hi @aarongerig,

Thanks a lot for the schema it helps a lot! Unfortunately, this is a very specific use case. I don’t think we have a built-in widget to implement such behavior. I would recommend creating your own widget with the logic implemented inside. It would be the simplest solution I think.

The suggestion from @cindy.cullen could simplify the logic though. With a numeric value, you can use a range rather than specifying the exhaustive list of facets. Here is an example with a filter on 2b:

(attribute >= 2 AND attribute < 6) OR (attribute >= 7 AND attribute < 11)
// vs
attribute:2b OR attribute:2c OR attribute:2d OR attribute:2e OR attribute:3b OR attribute:3c OR attribute:3d OR attribute:3e

Let me know if you have any questions!