Concepts / Managing results / Custom ranking
Jan. 07, 2019

Custom ranking

On this page

Custom ranking is the most direct and powerful way to adapt Algolia to your business. When you classify records with business metrics like bestseller, most popular, or highest rated, Algolia can ensure that your best products appear first to your clients. Customizing the order of your results is possible no matter the query, and no matter how unique or ambitious your business objectives. How to do this is often all you need to know about Algolia’s ranking strategy.

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”). Because of typo tolerance, records with “theatre” and “theater” will be found. Now, Algolia can re-use this same typo tolerance to rank records: all records that contain “theatre” will be ranked higher than records with “theater”. Essentially, the tie-breaking algorithm privileges the best matches - in this example, those that match the typo (i.e., all 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 sorts all matching records according to the first criterion (e.g., typos).
  • For all records that are tied (no typo), it sorts them according to the second criterion (geolocation).
  • If there are still records that are tied (they have the same geolocation), it sorts 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 is ranked higher than record 2. If, however, the movie theaters were within the same geo range, the engine will need 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, sorting 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:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    [
      {
        "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 sort 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?