Configuring Typo Tolerance
On this page
Enable, Disable, or More strict Typo Tolerance
Typo tolerance is enabled by default. For most clients, this is the best course of action. Other options include disabling it completely, or making it more strict. You control these options with the typoTolerance setting.
Other options include disabling typo tolerance completely, or limiting its effects.
You have 4 possibilities.
true
: Activate typo-tolerance (default, suggested value).false
: Disable typo-tolerance.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).strict
: Similar to 3, but keep the 2 lowest number of typos. This is useful when you want to ensure more results.
Some considerations
- When
typoTolerance
is enabled (set totrue
,min
orstrict
), we also enable splitting and concatenation. - When
typoTolerance
is set tostrict
, we force the Typo criterion to be first in the ranking formula. - When using a sort-by attribute, we recommend setting
typoTolerance
tomin
to reduce the number of potentially irrelevant search results.
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.
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 does not 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. We recommend passing an array of the specific ISO codes of languages you target. For example:
Granular Targeting of Typo-Tolerance
Typos Tolerance and Numerics
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 disable it in specific situations such as postal codes - if typos are enabled, any postal code query will return a lot of false positive results.
Disabling typo tolerance on a specific attribute
You can enable typo tolerance globally and disable it 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 disabled. This is useful, for example, with acronyms like “mysql,” “php”, or “mamp”.
Specifying Your Own Alternative Corrections
When default typo-tolerance is not enough, you can specify alternative corrections. Alternative corrections are synonyms that are not treated as exact matches. They are 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 above an alternative correction.