Product

Feature Spotlight: Query Rules
facebooklinkedintwittermail

You’re running an ecommerce site for an electronics retailer, and you’re seeing in your analytics that users keep searching for “cheap phones”. Right now, that’s leading to a ton of empty result sets, bounced users, and lost revenue, so your supervisor has tasked you with doing something about it.

One colleague suggested adding the word “cheap” to phone results that are under $400, but you know that’s not a good idea. Not only does having the word “cheap” in your product titles or description just sound like bad marketing, it’s completely unsustainable because product prices change all the time.

Another colleague suggested hardcoding a rule in your codebase to convert the word “cheap” in a query into a filter for products under $400, and while that’s definitely closer to the right solution, you can tell that’s not sustainable either. It requires putting more on the developers’ plate, creating your own system to handle the hardcoded rules, and keeping somebody with technical skills around to manually add more rules in the future.

Wouldn’t it be nice if your search engine handled the technicality of this for you and gave you a clean UI to manage these rules with?

Enter Algolia’s Query Rules.

Make filters from textual queries

The use-case described above is easy to fix with Algolia. Inside your search index, click on the Rules tab on the left and click “Create your first Rule”.

customize your search experience with query rules

Select the Visual Editor (this is the one that you don’t need technical skills to manage) and you’ll get a window like this:

Query rules visual editor

Start by choosing one of the three options in the top left. For our cheap phone example, try setting a query condition that triggers when the query contains the words “cheap phone”.

Setting query rule conditions

 

Then click Filter Results, so that when Algolia sees the user’s query and triggers this rule, it’ll filter how we expect:

Query rules category filters

Temporary pins

Another thing you can do with Query Rules is pin results based on some query trigger. For example, our fictional smartphone retailer probably wants the newest phones to show up in search results they match. But when you think about it, they’ll have very few views and sales, so there’s really no logical reason that the engine would prioritize these entries.

We can handle this with Query Rules. Let’s promote the (still-future-as-of-writing) iPhone 15 from September to December 2023 by setting a date range trigger:

Query rules date range trigger

 

Then click Pin items, select the result representing the iPhone 15, and keep the checkbox checked.

In our case, we only want the iPhone 15 pinned to the top of the search results if that’s actually what the user was searching for. The user experience could get really frustrating otherwise in our use-case – imagine searching for something else an electronics store would sell like a speaker system, but every search returns the latest iPhone in first place – but there are legitimate use-cases where it might be a good idea to untick this box.

You can use the same logic system to boost or bury certain product categories – noticing VR and AR products are skyrocketing in popularity and performing really well whenever users see them? Boost them in the search rankings to take advantage of the trend.

Perhaps you’re not going to be stocking some products for a while – maybe you could use a query rule to hide some items or boost their replacements. The possibilities are endless!

If you’re curious about how to use this to implement your great ideas, check out the more thorough docs here. Happy building!

About the authorJaden Baptista

Jaden Baptista

Technical Writer

Recommended Articles

Powered by Algolia AI Recommendations

Enhance & Promote Results: Introducing Query Rules
Product

Enhance & Promote Results: Introducing Query Rules

Nicolas Baissas

Nicolas Baissas

4 questions to ask for relevant search results
Product

4 questions to ask for relevant search results

Jaden Baptista

Jaden Baptista

Technical Writer
What is a search query and how is it processed by a search engine?
Product

What is a search query and how is it processed by a search engine?

Catherine Dee

Catherine Dee

Search and Discovery writer