Guides / Managing results / Optimize search results / Typo tolerance

Configuring Typo Tolerance

Configuring typo tolerance

Typo tolerance is on by default. Usually, this is the best course of action. Other options include turning it off completely, or making it more strict. You control these options with the typoTolerance setting.

You have 4 options to configure the typo tolerance:

  1. true: Activate typo-tolerance (default, suggested value).
  2. false: Disable typo-tolerance.
  3. min: Only keep results with the lowest number of typos. This means that if you have 1 or more records that match, you’ll only receive those records; but if you have no records that match, you’ll receive records with typo counts of 1 (or 2 if there are none with 1).
  4. strict: Similar to 3, but keep the 2 lowest number of typos. This is useful when you want to ensure more results.
API Reference typoTolerance

Some considerations

Configuring word length for typos

Word length for 1 typo

Typos are only tolerated when the query reaches a certain character length. The default is 4 - this means that the engine waits for the user to enter 4 characters before applying typo tolerance.

You can override this default with the minWordSizefor1Typo setting. As soon as a word contains at least minWordSizefor1Typo characters, the engine will allow one typo in matches.

API Reference minWordSizefor1Typo

Word length for 2 typos

An additional setting is to tell the engine when to start considering 2 typos. As soon as the query contains at least minWordSizefor2Typos characters, the engine will allow up to two typos in matches. Default is 8 characters.

Typos are counted per-word. In the case of multi-word queries, it’s possible for each word of the query up to 2 typos, according to minWordSizefor1Typo and minWordSizefor2Typo.

Treating singulars and plurals as equivalent

By default, Algolia doesn’t consider singulars and plurals as matches. You can override this default behavior by setting ignorePlurals to true.

If activated, this feature is designed to match words written in the plural form even if the query is in the singular form, and vice-versa. It’s built on a dictionary of singular and plural forms of words in over eighty languages. It works for simple plurals like hand ⇄ hands as well as more complex ones like feet ⇄ foot.

This parameter accepts a boolean or array value. You should pass an array of the specific ISO codes of languages you target. For example:

API Reference ignorePlurals

Granular targeting of typo tolerance

Typos tolerance and numeric attributes

By default, numeric attributes are included in the typo tolerance logic. This allows for one or two wrong numbers in a telephone number. It makes sense to turn it off in specific situations such as postal codes - with typo tolerance, any postal code query will return a lot of false positive results.

Disabling typo tolerance on a specific attribute

You can turn on typo tolerance globally and turn it off for specific attributes. This is useful, for example, with products that might require SKU search without typo-tolerance.

Disabling typo tolerance for certain words

You can define a list of words for which typo tolerance should be turned off. This is useful, for example, with acronyms like “mysql,” “php”, or “mamp”.

Specifying your own alternative corrections

When default typo tolerance isn’t enough, you can specify alternative corrections. Alternative corrections are synonyms that aren’t treated as exact matches. They’re grouped and interpreted as words with typos : you can determine how many typos the word is assigned with altCorrection{number of typos}.

For example, if you made a synonym for “cell” <=> “mobile”, a query for “cell” would return records with “mobile” with a score of 0 typos and vice versa. If you make an altCorrection1 for “cell” => “mobile”, a query for “cell” returns records with “cell” first (as zero typo results), then records with “mobile” (as one typo results). If you make an atlCorrection2 for “cell” => “mobile”, a query for “cell” returns records with “cell” first (as zero typo results), then records with “cel*” (as one typo results), then records with “mobile” (as two typo results).

Alternative correction creates penalized synonyms. Using altCorrection2 prioritizes the “original” term and minor typos over an alternative correction.

Did you find this page helpful?