How to create a Query Rule to transform a dynamic value into an dynamic interval

Hi guys,

I was wandering how can i create an query rules for the following scenario:
The user enters in search box a query term that contains a value, let’s say 75000 €

I want to create an dynamic query rule to filter results based on a “facet:sale_price” to match an interval: 70000 TO 80000
The 75000 is a generic value. I want to catch this value and substract/add 5000 to create an interval.

See the image below

Thanks in advance for helping me :slight_smile:

Hi there, this is currently tracked on our side but there’s no way to achieve it with query rules. Dynamic query rule is a good name for this feature yes.

Your best bet for now would be to implement that on your client/frontend side.
With a good regex you will be able to catch customers that are typing prices in the query field then you can implement dynamic filters yourself when sending the query to Algolia.

Good luck!

Thanks Vincent for your quick reply!

Your solution sounds good, but how can i implement it using instantsearch? I guess i have to build a custom connector, right?

Best bet would be to use this: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-searchfunction

As a way to hook when the search client is gonna make a query, and then use helper methods like https://community.algolia.com/algoliasearch-helper-js/reference.html#AlgoliaSearchHelper#setQueryParameter to then update the “filters” parameter with your numeric filter.

Yes, this will do the trick.
Thanks again!