phnoe instead of phone. You can configure the typo tolerance feature for each index.
enabled
Typo tolerance is enabled by default, but you can disable it if needed:
phnoe will no longer return a document containing the word phone.
In most cases, keeping typo tolerance enabled results in a better search experience. Massive or multilingual datasets may be exceptions, as typo tolerance can cause false-positive matches in these cases.
minWordSizeForTypos
By default, Meilisearch accepts one typo for query terms containing five or more characters, and up to two typos if the term is at least nine characters long.
If your dataset contains seven, searching for sevem or sevan will match seven. But tow won’t match two as it’s less than 5 characters.
You can override these default settings using the minWordSizeForTypos object. The code sample below sets the minimum word size for one typo to 4 and the minimum word size for two typos to 10.
minWordSizeForTypos object, keep in mind that:
oneTypomust be greater than or equal to 0 and less than or equal totwoTypostwoTyposmust be greater than or equal tooneTypoand less than or equal to255
0 ≤ oneTypo ≤ twoTypos ≤ 255.
We recommend keeping the value of oneTypo between 2 and 8 and the value of twoTypos between 4 and 14. If either value is too low, you may get a large number of false-positive results. On the other hand, if both values are set too high, many search queries may not benefit from typo tolerance.
disableOnWords
You can disable typo tolerance for a list of query terms by adding them to disableOnWords. disableOnWords is case insensitive.
Shrek or shrek at search time to match documents.
disableOnAttributes
You can disable typo tolerance for a specific document attribute by adding it to disableOnAttributes. The code sample below disables typo tolerance for title:
title attribute will not tolerate any typos. For example, a search for beautiful (9 characters) will not match the movie “Biutiful” starring Javier Bardem. With the default settings, this would be a match.
disableOnNumbers
You can disable typo tolerance for all numeric values across all indexes and search requests by setting disableOnNumbers to true:
2024 matching documents containing 2025 or 2004.
When disableOnNumbers is set to true, queries with numbers only return exact matches. Besides reducing the number of false positives, disabling typo tolerance on numbers may also improve indexing performance.
How typo tolerance works
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 allowed typos 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:- Substitution of a character (for example,
kitten→sitten) - Insertion of a character (for example,
siting→sitting) - Deletion of a character (for example,
saturday→satuday)
- If the query word is between
1and4characters, no typo is allowed. Only documents containing words that start with or are of the same length as the query word are considered - If the query word is between
5and8characters, one typo is allowed - If the query word contains more than
8characters, a maximum of two typos is allowed
saturday (8 characters) uses the second rule and matches with one typo:
saturdayis accepted (exact match)satudayis accepted (one typo)sutudayis not accepted (two typos)caturdayis not accepted (a typo on the first letter counts as two typos)
Impact on the typo ranking rule
The typo ranking rule sorts search results by increasing number of typos on matched query words. Documents with 0 typos 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 typo tolerance effectively also disables the typo ranking rule, because all returned documents will contain 0 typos.
- Typo tolerance affects how lenient Meilisearch is when matching documents
- The
typoranking rule affects how Meilisearch sorts its results - Disabling typo tolerance also disables the
typoranking rule