Typo tolerance helps users find relevant results even when their search queries contain spelling mistakes or typos.
phnoe
instead of phone
. You can configure the typo tolerance feature for each index.
Meilisearch uses a prefix Levenshtein algorithm to determine if a word in a document could be a possible match for a query term.
The number of typos referenced above is roughly equivalent to Levenshtein distance. The Levenshtein distance between two words M and P can be thought of as “the minimum cost of transforming M into P” by performing the following elementary operations on M:
kitten
→ sitten
)siting
→ sitting
)saturday
→ satuday
)1
and 4
characters, no typo is allowed. Only documents that contain words that start with or are of the same length with this query word are considered valid5
and 8
characters, one typo is allowed. Documents that contain words that match with one typo are retained for the next steps.8
characters, we accept a maximum of two typossaturday
which is 7
characters long, uses the second rule and matches every document containing one typo. For example:
saturday
is accepted because it is the same wordsatuday
is accepted because it contains one typosutuday
is not accepted because it contains two typoscaturday
is not accepted because it contains two typos (as explained above, a typo on the first letter of a word is treated as two typos)typo
ranking ruletypo
ranking rule sorts search results by increasing number of typos on matched query words. Documents with 0 typos will rank highest, followed by those with 1 and then 2 typos.
The presence or absence of the typo
ranking rule has no impact on the typo tolerance setting. However, disabling the typo tolerance setting effectively also disables the typo
ranking rule. This is because all returned documents will contain 0
typos.
To summarize:
typo
ranking rule affects how Meilisearch sorts its resultstypo