FuzzyQuery

class FuzzyQuery(term: Term, maxEdits: Int = defaultMaxEdits, prefixLength: Int = defaultPrefixLength, maxExpansions: Int = defaultMaxExpansions, transpositions: Boolean = defaultTranspositions, rewriteMethod: MultiTermQuery.RewriteMethod = defaultRewriteMethod(maxExpansions)) : MultiTermQuery

Implements the fuzzy search query. The similarity measurement is based on the Damerau-Levenshtein (optimal string alignment) algorithm, though you can explicitly choose classic Levenshtein by passing false to the transpositions parameter.

This query uses MultiTermQuery.TopTermsBlendedFreqScoringRewrite as default. So terms will be collected and scored according to their edit distance. Only the top terms are used for building the BooleanQuery. It is not recommended to change the rewrite mode for fuzzy queries.

At most, this query will match terms up to {@value

  • LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE} edits. Higher distances (especially with transpositions enabled), are generally not useful and will match a significant amount of the term dictionary. If you really want this, consider using an n-gram indexing technique (such as the SpellChecker in the {@docRoot}/../suggest/overview-summary.html) instead.

NOTE: terms of length 1 or 2 will sometimes not match because of how the scaled distance between two terms is computed. For a term to match, the edit distance between the terms must be less than the minimum length term (either the input term, or the candidate term). For example, FuzzyQuery on term "abcd" with maxEdits=2 will not match an indexed term "ab", and FuzzyQuery on term "a" with maxEdits=2 will not match an indexed term "abc".

Constructors

Link copied to clipboard
constructor(term: Term, maxEdits: Int = defaultMaxEdits, prefixLength: Int = defaultPrefixLength, maxExpansions: Int = defaultMaxExpansions, transpositions: Boolean = defaultTranspositions, rewriteMethod: MultiTermQuery.RewriteMethod = defaultRewriteMethod(maxExpansions))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
open val field: String

Returns the field name for this query

Link copied to clipboard
Link copied to clipboard

Returns the non-fuzzy prefix length. This is the number of characters at the start of a term that must be identical (not fuzzy) to the query term if the query is to match that term.

Link copied to clipboard
open val termsCount: Long
Link copied to clipboard

Returns true if transpositions should be treated as a primitive edit operation. If this is false, comparisons will implement the classic Levenshtein algorithm.

Functions

Link copied to clipboard
open fun createWeight(searcher: IndexSearcher, scoreMode: ScoreMode, boost: Float): Weight

Expert: Constructs an appropriate Weight implementation for this query.

Link copied to clipboard
open operator override fun equals(obj: Any?): Boolean

Override and implement query instance equivalence properly in a subclass. This is required so that QueryCache works properly.

Link copied to clipboard
fun getTerm(): Term

Returns the pattern term.

Link copied to clipboard

Constructs an enumeration that expands the pattern term. This method should only be called if the field exists (ie, implementations can assume the field does exist). This method never returns null. The returned TermsEnum is positioned to the first matching term.

Link copied to clipboard
open override fun hashCode(): Int

Override and implement query hash code properly in a subclass. This is required so that [ ] works properly.

Link copied to clipboard
open override fun rewrite(indexSearcher: IndexSearcher): Query

To rewrite to a simpler form, instead return a simpler enum from .getTermsEnum. For example, to rewrite to a single term, return a SingleTermsEnum

Link copied to clipboard
open override fun toString(field: String?): String

Prints a query to a string, with field assumed to be the default field and omitted.

open override fun toString(): String

Prints a query to a string.

Link copied to clipboard
open override fun visit(visitor: QueryVisitor)

Recurse through the query tree, visiting any child queries.