Web / Apache Lucene Interview questions
Which is better and why: FuzzyQuery vs WildcardQuery for typo tolerance?
Neither is universally "better" - they solve different problems, and picking the wrong one for typo tolerance produces frustrating results.
FuzzyQuery matches terms within a bounded edit distance (insertions, deletions, substitutions), which is exactly what typos are - it correctly matches "lucne" to "lucene" without the user specifying where the letters are missing.
WildcardQuery matches a literal pattern with * and ? placeholders that the user must position correctly - it has no concept of "close enough" spelling, so it can't help if the user doesn't know exactly which characters are wrong or missing. It's also considerably more expensive when the wildcard leads the pattern, since it can't use the term dictionary's prefix ordering.
For genuine typo tolerance, FuzzyQuery (or a dedicated suggester) is the right tool; WildcardQuery fits known partial-pattern matching, like a curated "starts with" search.
More Related questions...