Guides / Managing results / Rules

Queries contain keywords, terms that are especially indicative of what a user is looking for. However, these keywords are not universal. They vary based on your catalog and products. For a clothing company, the word “red” in a query likely indicates that a user is searching for red articles. For a film database however, “red” is probably unrelated to a color category.

Once you determine the intended effect of specific query terms or phrases, you can dynamically change your users’ results when their search matches those terms. Algolia lets you configure this using Rules.

Rules can respond to specific queries. When encountering certain query terms or phrases, they can modify your users’ search results in a predefined way.

Rules are also an effective way to merchandise and promote products.

Knowing user intent, you can set up rules that refine responses by:

  • Adding filters
  • Creating new settings
  • Personalizing results
  • Changing the entire query to better match the data in your index.

This section provides an overview of the most popular (but not exhaustive) ways of detecting and responding to user intent with rules.

Automatic and dynamic filtering based on the query

Consider the query “cheap toaster 800w”. Rules can be used to filter the results by category “toaster” and prices between 0 and 25, so that the only textual search is the remaining term “800w”. This would further limit the results with that specific wattage.

Rules can modify responses by adding filters depending on the query, which can return more relevant results.

Altering the query by recognizing categories

An example of altering a query is with an online document library that allows keyword searches inside documents. If a user searches for “article ref21”, they’re probably signaling to the system that they’re looking for an article whose title or identifier contains “ref21”. The term “article”, in this context, is a category, while “ref21” is an identifier.

Currently, Algolia wouldn’t return the expected results, because the engine would search for the terms “article” and “ref21”, but the records likely don’t contain the term “article”.

Rules can fix this: when seeing the pattern “article ref”, you can remove the word “article”. By doing that, “article ref21” would be replaced by “ref21”,

Rules were designed with this use case in mind. You can make Rules that recognize and removes categories from a search query, focusing the search exclusively on the informative content of the query.

Replacing words

This feature is comparable to synonyms. Algolia’s synonyms expand a search by adding words with similar meanings. When you create a synonym, the engine searches both the typed word and its synonym. However, what if you wanted to search only the synonym?

Rules offers an alternative. You can now replace words instead of adding new ones.

For example, if you make “tv” a synonym for “television”, Rules will replace “tv” with “television” so that only “television” is used to search, as opposed to synonyms, which would search for both “tv” and “television”.

Rules can reduce the noise that can come from synonyms.

Replacing the entire query

You can also use Rules to replace an entire query with an alternative set of words or phrases.

This use case is slightly different: consider a query that refers to a product informally and indirectly, using words that aren’t in your records. You can remove the common phrase from the query and replace it with your own vocabulary.

An example of this is a query for “apple phone” which you can replace with “iphone”.

Applying search parameters

Perhaps the most flexible and powerful Rules feature is the ability to add or change search settings on the fly. After parsing a query, your Rule can determine which settings best apply to the given search.

For example, depending on the search, you can turn typo tolerance on or off, change geolocation settings, search for only certain types of attributes, or add filters.

Did you find this page helpful?