Dataset example
In the following dataset, some movies have Clint Eastwood as an actor, some as a director, and some have both.JSON
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
-
Set
director
asattributesForFaceting
. This happens at indexing time. -
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'
.
saveRule
method.
Using the dashboard
You can also add your Rules in Algolia’s dashboard.- Select the Search product icon on your dashboard and then select your index.
- Click the Configuration tab.
-
In the Facets subsection of Filtering and Faceting, click the “Add an attribute” button and select the
director
attribute from the dropdown. - Select the Rules section from the left sidebar menu in the Algolia dashboard.
- Under the heading Rules, select the index to which you’re adding a Rule.
- Select Create your first rule or New rule. In the dro-down menu, click the Manual Editor option.
-
In the Condition(s) section, keep Query toggled on, select Contains in the drop-down menu, and select the option Add Facet “director” from the input box.
{facet:director}
should then be displayed. -
In the Consequence(s) section:
- Click the Add consequence button and select Filter Matching Attributes (or Filter/Boost Matching Attributes).
- In the Filter input that appears, select the option Add Facet “director” in the dropdown.
- Click the Add consequence button again and select Remove Word.
- In the input that appears, select Remove
{facet:director}
.
- Save your changes.