Concepts / Managing results / Custom ranking
Jul. 17, 2019

Custom Ranking

The main goal of search is to empower users to find what they are looking for. This can be broken down into two crucial steps: returning accurate results and ranking them. This page focuses on what ranking is and how you can impact it with custom ranking.

Algolia’s ranking strategy orders results first by default criteria and then by custom ranking. People are often confused that custom ranking comes after default ranking. This is the case because Algolia’s default criteria ensure that users find what they are looking for, while custom ranking helps you increase visibility for some of your most important products. With this in mind, ensure that increasing visibility does not prevent users from finding what they are looking for.

Custom ranking remains a direct and powerful way to adapt Algolia to your business. When you classify records with business metrics like bestseller, most popular, or highest rated, your best products appear higher in your results.

However, it’s important to understand that Custom Ranking is only one element in Algolia’s overall ranking strategy. In fact, it is one among eight criteria, where each plays a significant role in ordering your records. Let’s take a look at how this works.

Algolia’s Ranking Strategy

Ranking is the second half of the relevancy equation. Once the engine has found matching records (the first half of relevance), it needs to order those records, putting the best matches at the top, preferably on page 1.

The Ranking Criteria

It does this by using a tie-breaking algorithm, which re-uses much of the same textual matching criteria to determine the best matches.

A good example is typos. When searching for a movie theater, you accidentally type “theatre” (swapping the “er”). Thanks to typo tolerance, the engine will return records with “theatre” (exact match) and “theater” (match with a single typo). Now, Algolia can re-use typo tolerance to rank records: all records that contain “theatre” will rank higher than records with “theater”. Essentially, the tie-breaking algorithm privileges the best matches - in this example, those that exactly match the search term with a typo (i.e., records with “theatre”).

Ranking criteria include in order:

There are 8 in all, and they all play a role in ranking by breaking ties.

The order of criteria can be changed, but we recommend using the out-of-the-box ranking order as it works well for the vast majority of use cases.

How Tie-Breaking Works

Most search engines use a coefficient-based approach and rank results based on a unique float value that is hard, if not impossible, to decipher.

Algolia has built its own approach, using a tie-breaking algorithm. Here’s how it works:

  • It orders all matching records according to the first criterion (number of typos, so exact matches rank first).
  • For all records that are tied, it orders them according to the second criterion (geolocation).
  • If there are still records that are tied (they have the same geolocation), it orders them according to the third criterion (filters) and so on, until each record in the search results has a distinct position.
  • If, after going through this process, the tie cannot be broken, Algolia will use one or more of your customized ranking attributes to break the tie, as discussed below.

Going back to our “theatre” example. If 2 records have the same spelling (“theatre”), they will be tied. The algorithm needs to break the tie. The next criterion is Geo. If record 1 is geographically closer to the user than record 2, then the Geo criterion breaks the tie, and record 1 ranks higher than record 2. If, however, the movie theaters were within the same geo range, the engine needs to go to the 3rd criterion, which we’ll say is Filters. If the query is “movie theatre 4D”, and only record 2 has a filter on “4d”, then record 2 breaks the tie and will be ranked above record 1. And so on with all 8 criteria.

Custom Ranking

Finding matching records using typos, geolocation, filters, and so on, is only part of what makes a compelling search experience. Algolia’s default ranking formula works well to handle this kind of record-matching relevance.

However, ordering on such properties alone undermines the value of thoughtfully ordering results based on custom metrics within each record. Custom Ranking gives you direct control over the ranking and is often the deciding factor on which records appear in the first set of results.

Here are some examples that add popularity to the ranking formula. When you type “spielberg films”, the custom ranking puts his most popular films at the top of the results. If you type “t-shirt”, then the most popular t-shirts appear at the top. For a blog website, if you type in “think positive”, the most popular articles on that subject appear at the top.

Typical custom ranking attributes include:

  • number of sales, views, or likes
  • ratings
  • date of release

This kind of control over ranking allows you to achieve many business goals: to showcase your product-line, to encourage people to stay on your site and view as many products as possible, to increase sales, among others.

Defining a custom ranking - leveraging business metrics to rank search results effectively - is crucial for any successful search configuration.

An Example of Custom Ranking

Let’s take a look at a common use case:

  • Dataset:

        "name": "iPhone 6 Plus",
        "popularity": 20
        "name": "iPhone 6",
        "popularity": 10
        "name": "iPhone 7",
        "popularity": 200
  • Custom ranking: Descending popularity

With this configuration, if an end user were to type the query “iPhone”, he/she would get the following results: Iphone 7 will be first, followed by iPhone 6 Plus and iPhone 6.

You can decide whether you want the order to be descending (bigger values appear first in the results) or ascending (smaller values appear first in the results).

Custom Ranking precision

Tie-breaking only works if there are records that are tied to begin with. If a particular custom ranking metric is too precise, then the next custom metric will essentially be ignored. For this reason, we stress the importance of ‘reducing precision’ to allow tie-breaking to be effectively leveraged.

Imagine a custom ranking configuration that sets both ‘rating’ and ‘count’ as custom ranking attributes. If the rating for a record is too precise - say ‘“rating”: 4.321321’ - then the count will likely not be used to break the tie.

To fix the situation, we recommend creating another attribute, say ‘truncated_rating’, where we will only take values to the nearest tenth. In this example, 4.321321 becomes 4.3. By reducing the precision of the ‘rating’ attribute, we allow a higher probability that there will be several records that also have a ‘truncated_rating’ of 4.3; thus, we allow the possibility for tie-breaking on the ‘count’ attribute.

Custom Ranking - A 6-Minute Video

Did you find this page helpful?