Unveiling the search algorithm: how Algolia improved search

Nicolas Dessaigne3 Aug 2023

Problem

Many search engines score each document with one opaque float, usually based on how often the query words occur in it. Nobody can explain such a score, so relevance is hard to improve, and the approach fits other data formats badly. Mixing relevance with popularity is a second pain. Sorting by relevance ignores sales or ratings, and sorting by popularity can put outrageously popular but irrelevant results on top. Prefix matching, in contrast, returns relevant results after a single typed letter.

Example from the article: a five-record contact list (names, companies, number of calls) searched for "joe black", where typos, word proximity and call counts must settle the order.

Solution in brief

Give each matching record a separate integer score per criterion and sort by the criteria in a fixed order: each later criterion breaks only the ties left by the earlier ones. Business metrics are added as the last criterion, so they order records that are equally relevant. Matching is done on prefixes of words, so results appear from the first typed letter.

Questions this case answers
  • How to order retrieved records by several relevance signals and a business metric so that the order is deterministic and explainable per record
  • How to keep a popularity signal from overriding query relevance when both must decide the order of results
  • How to rank search results so that typos, word proximity, field priority and popularity are all taken into account in a predictable order?
  • How to blend a business metric such as popularity into relevance without letting irrelevant but popular records win?

Tools and methods

  • Tie-breaking multi-criteria ranking — typos, geo-distance, proximity, attributes, exact, custom, compared in that order
  • Prefix matching — search-as-you-type on the last query word
  • Custom ranking — a business metric (such as call count) as the final tie-breaker, computed at index time
Continue reading — it's free

Google or a one-time email code. No password.