Dataset example
Back to the Twitter example: assume you have an index calledtwitter_accounts that looks like this:
JSON
nb_followers,
because Algolia prioritizes exact results,
the @BarakObama account would benefit from the traffic coming from users making a typo when searching for the official Barack Obama account.
You can short-circuit this issue with Algolia’s sort-by-attribute feature.
Update the dataset
The recommended solution is to add a boolean attributes that separates popular records from the rest. For example, you could add something likeis_verified_account = true,
or is_popular = true, and sort on that attribute.
You have a popularity metric (nb_followers),
so you can use it to define a rule that determines if a record is popular or not.
In this example, you could say that a user is popular if they have more than a million followers.
To run the code examples on this page, install the latest API client.
You can use the browse method to update the index:
JSON
typo rule—the sort-by attribute.
When your ranking has been applied,
searching for “BarakObama” returns the “BarackObama” record first.
Add a sort-by attribute in the dashboard
- Go to the Algolia dashboard and select your Algolia .
- On the left sidebar, select Search.
- Select your Algolia index.
- On the Configuration tab, select Ranking and Sorting.
- Click Add sort-by attribute and type or select your attributes.
- Save your changes.
Add a sort-by attribute with the API
To set a sort-by attribute, you need to use theranking with the setSettings method.