Typo tolerance
On this page
A typo is a typing mistakes or spelling error. For example:
- A missing letter: “hllo” → “hello”
- An extraneous letter: “heello” → “hello”
- Inverted letters: “hlelo” → “hello”
- Substituted letter: “heilo” → “hello”
What’s typo tolerance?
Typo tolerance lets users make mistakes while typing but still find the records they’re looking for. This is done by matching words that are close in spelling.
Tolerating typos is fundamental to modern search experiences for two reasons:
- Typos are inevitable on mobile devices.
- Because products and services are growing in both complexity and global reach, not everyone knows the right way to spell a word.
Algolia provides typo tolerance out-of-the-box, along with some important ways to customize just how tolerant a search experience should be.
How typos are calculated
Algolia’s algorithm for dealing with typos is based on the difference in spelling between a query word and its exact match in the index: the distance.
Calculating distance
Distance is the count of operations (additions, deletions, substitutions, or transpositions) needed to change one word into another.
For example, the query “strm” might mean “storm” or “strum” (distance=1), “star” or “warm” (distance=2). The following examples illustrate the calculated distances between various search queries and the target word “Michael”.
- michael = 0. Algolia isn’t case-sensitive (“michael” = “Michael”)
- mickael = 1 (substitution: h → k)
- micael = 1 (deletion: h)
- mickhael = 1 (addition: k)
- micheal = 1 (transposition: a ⇄ e)
- mickaell = 2 (substitution: h → k, addition: l)
- Tichael = 2 (substitution: m → T, first letter)
- Tickael = 3 (substitution: m → T, first letter, substitution h → k).
Algolia handles up to two typos in a word. An exception is made for words with three typos but only if the first typo occurs on the initial letter. The final item in the preceding example (“Tickael”) illustrates this.
Typo tolerance is ignored for:
- Logogram-based languages, such as Chinese and Japanese, use pictures to represent words (or partial words). Typo tolerance only applies to phonemic languages (such as English, French, and Russian), where characters represent sounds to form words.
- Punctuation and special characters
- Splits and concatenations (insertion or removal of spaces between two words)
- Any user query between quotes (if you’ve enabled
advancedSyntax
).
Impact of typos on the ranking formula
Typo count is the first criterion in Algolia’s ranking formula. This means that words with perfect matches (no typos) rank higher than words with one typo, and one-typo words rank higher than words with two typos. There’s also a special ranking rule if there’s a typo on the first letter.
Configure typo tolerance settings
Enabling typo tolerance is often enough but certain queries or datasets require fine-tuning the settings. For more information, see Configuring typo tolerance.