Skip to main content
When creating a rule, it’s not uncommon to set more than one consequence. A good example is when you want to use a search term as a or a value but not for textual search. Consider a website where users can search for movies by title, actor, or director. Some actors, like Clint Eastwood are also directors: people searching for “clint eastwood” might not be looking for the same thing. For example, people looking only for movies directed by Clint Eastwood might search for “clint eastwood director”, hoping to filter out every movie that Clint Eastwood plays in but didn’t direct. In this case, you wouldn’t be interested in the word “director for textual search purposes, but as a cue to set a filter. You would therefore want to remove the word “director” from the so that Algolia doesn’t textually look for matching that word. You can achieve this by combining several consequences in your rule.

Dataset example

In the following dataset, some movies have Clint Eastwood as an actor, some as a director, and some have both.
JSON
If someone searches for “clint eastwood”, they would retrieve all movies by or with Clint Eastwood, even if they were only interested in movies with Clint Eastwood as the director. You could solve this problem with faceting, by setting director as an attribute for faceting and providing a refinement list with its own search input on your frontend. Yet, an even better way of helping your users would be to make your search smart and look only for movies where director is equal to “Clint Eastwood” whenever they type “clint eastwood director”. To achieve this, you first need to set director in your list of attributes for faceting. Then, you can create a new Rule that filters on matching attributes. You need to create two consequences whenever a user types in “clint eastwood director”:
  • Filter all results with “director”
  • Remove the word “director” from the search

Using the API

To run the code examples on this page, install the latest API client.
  1. Set director as attributesForFaceting. This happens at indexing time.
  2. Set a Rule that:
    • Detects the term “director” in a query whenever it comes after a term that matches the name of a director
    • Applies a filter on facet value director:'Clint Eastwood'.
    To do this, use the saveRule method.
However, setting the Rule isn’t enough. Even when you set a Rule, the engine still tries to match the terms in the query. If a user searches for “clint eastwood director”, even if your Rule applies, the engine will look for the word “director” in the records. With the example dataset, this wouldn’t return any results at all. This is where combining consequences comes in handy. When this Rule applies, you can add another consequence to remove the word “director” from the query. This way, the engine will only use it for filtering, not search.

Using the dashboard

You can add this rule from the Algolia dashboard using either the Visual Editor or the Manual Editor.

Preparation

  1. Select Search in the Algolia dashboard and select your .
  2. Open Configuration > Filtering and Faceting > Facets.
  3. Click Add an attribute and select director.
  1. Open Rules and select New rule > Visual Editor.
  2. Click Set query condition(s) and select Contains. Enter { to select the director facet placeholder, then add the literal word director after it. The pattern is {facet:director} director. Click Apply.
  3. In Consequences, expand More consequences and select Filter / Boost matching attribute. Select director in Facet, choose Filter, and click Apply. If your plan doesn’t support boosting, select Filter facets instead.
  4. Click Add Consequence, expand More consequences, and select Remove word. In Word(s), enter the literal word director, keeping the director’s name in the search query. Click Apply.
  5. Preview clint eastwood director, click Review and Publish, and click Publish.
Last modified on September 28, 2026