Configuring typo tolerance
On this page
Typo tolerance is on by default. You can change the typo tolerance behavior in the Typo-Tolerance section of Algolia’s dashboard or with the typoTolerance
parameter:
true
: Turns typo tolerance on (the default, suggested value).false
: Turns typo tolerance off.min
: Only keeps results with the lowest number of typos. This means that if you have one 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). When using a sort-by attribute, set typo tolerance tomin
to reduce irrelevant search results.strict
: Similar tomin
but keeps the two lowest number of typos. This is useful when you want to ensure more results. When typo tolerance isstrict
, the Typo criterion is forced to be first in the ranking formula.
When typo tolerance is true
, min
or strict
, the engine enables splitting and concatenation.
Configuring word length for typos
Typos are counted per word, and each word in the query can have up to two typos:
- One typo. Typos are only considered when a word in the query reaches a certain length. The default is 4 characters. This means that the engine waits for the user to enter four characters before applying typo tolerance. Change this default with the
minWordSizefor1Typo
parameter or the Min chars to accept 1 typo setting in the dashboard. - Two typos. You can tell the engine when to start considering two typos. The default is 8 characters. Change this default with the
minWordSizefor2Typos
parameter or the Min chars to accept 2 typos in the dashboard.
Treating singular and plural words as equivalent
Singular and plural word forms aren’t equivalent by default: foot ≠feet
.
Change this default behavior, so that foot = feet
, by setting the ignorePlurals
parameter to true
, or in the Language configuration page in the dashboard.
Typo tolerance and numbers
Typo tolerance is active on numbers by default. This, for example, allows users to make one or two wrong entries in a telephone number. For attributes such as postal codes, it makes sense to turn off typo tolerance for numbers since any typo will return many false positive results.
Change this default behavior by setting the allowTyposOnNumericTokens
parameter to false
or in the Typo-Tolerance section in the dashboard.
Turning off typo tolerance for specific attributes
You can turn off typo tolerance for specific searchable attributes. This is useful, for example, to turn off typo tolerance on product SKU codes.
Specify the attributes with the disableTypoToleranceOnAttributes
parameter or in the Typo-Tolerance section in the dashboard.
Turning off typo tolerance for certain words
You can define a list of words for which you wish to turn typo tolerance off. This is useful, for example, with acronyms like “mysql,” “php”, or “mamp”.
Specify the words with the disableTypoToleranceOnWords
parameter or in the Typo-Tolerance section in the dashboard.
Alternative corrections
Alternative corrections are synonyms that aren’t exact matches and are interpreted as words with one or two typos. Use them when you want to rank exact matches higher than synonym matches.
For example, compare (one-way) and alternative correction synonyms for cell <=> mobile
:
- One-way. A query for “cell” returns records containing “mobile” as 0 typo results.
- Alternative correction (one typo). A query for “cell” returns records containing “cell” first (as 0 typo results), then records with “mobile” (as 1 typo results).
- Alternative correction (two typos). A query for “cell” returns records containing “cell” first (as 0 typo results), then records with “cel*” (as 1 typo results), then records with “mobile” (as 2 typo results).