Class FuzzyQuery
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.TopTermsScoringBooleanQueryRewrite
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
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
suggest module) 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".
Inheritance
System.Object
FuzzyQuery
Assembly: Lucene.Net.dll
Syntax
public class FuzzyQuery : MultiTermQuery
Constructors
|
Improve this Doc
View Source
FuzzyQuery(Term)
Declaration
public FuzzyQuery(Term term)
Parameters
Type |
Name |
Description |
Term |
term |
|
|
Improve this Doc
View Source
FuzzyQuery(Term, Int32)
Declaration
public FuzzyQuery(Term term, int maxEdits)
Parameters
Type |
Name |
Description |
Term |
term |
|
System.Int32 |
maxEdits |
|
|
Improve this Doc
View Source
FuzzyQuery(Term, Int32, Int32)
Declaration
public FuzzyQuery(Term term, int maxEdits, int prefixLength)
Parameters
Type |
Name |
Description |
Term |
term |
|
System.Int32 |
maxEdits |
|
System.Int32 |
prefixLength |
|
|
Improve this Doc
View Source
FuzzyQuery(Term, Int32, Int32, Int32, Boolean)
Create a new FuzzyQuery that will match terms with an edit distance
of at most maxEdits
to term
.
If a prefixLength
> 0 is specified, a common prefix
of that length is also required.
Declaration
public FuzzyQuery(Term term, int maxEdits, int prefixLength, int maxExpansions, bool transpositions)
Parameters
Type |
Name |
Description |
Term |
term |
The term to search for
|
System.Int32 |
maxEdits |
Must be >= 0 and <= MAXIMUM_SUPPORTED_DISTANCE.
|
System.Int32 |
prefixLength |
Length of common (non-fuzzy) prefix
|
System.Int32 |
maxExpansions |
The maximum number of terms to match. If this number is
greater than MaxClauseCount when the query is rewritten,
then the maxClauseCount will be used instead.
|
System.Boolean |
transpositions |
true if transpositions should be treated as a primitive
edit operation. If this is false , comparisons will implement the classic
Levenshtein algorithm.
|
Fields
|
Improve this Doc
View Source
DefaultMaxEdits
Declaration
public const int DefaultMaxEdits = null
Field Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
DefaultMaxExpansions
Declaration
public const int DefaultMaxExpansions = null
Field Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
DefaultMinSimilarity
Declaration
public const float DefaultMinSimilarity = null
Field Value
Type |
Description |
System.Single |
|
|
Improve this Doc
View Source
DefaultPrefixLength
Declaration
public const int DefaultPrefixLength = null
Field Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
DefaultTranspositions
Declaration
public const bool DefaultTranspositions = null
Field Value
Type |
Description |
System.Boolean |
|
Properties
|
Improve this Doc
View Source
MaxEdits
Declaration
public virtual int MaxEdits { get; }
Property Value
Type |
Description |
System.Int32 |
The maximum number of edit distances allowed for this query to match.
|
|
Improve this Doc
View Source
PrefixLength
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.
Declaration
public virtual int PrefixLength { get; }
Property Value
Type |
Description |
System.Int32 |
|
|
Improve this Doc
View Source
Term
Returns the pattern term.
Declaration
public virtual Term Term { get; }
Property Value
|
Improve this Doc
View Source
Transpositions
Returns true
if transpositions should be treated as a primitive edit operation.
If this is false
, comparisons will implement the classic Levenshtein algorithm.
Declaration
public virtual bool Transpositions { get; }
Property Value
Type |
Description |
System.Boolean |
|
Methods
|
Improve this Doc
View Source
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
|
Improve this Doc
View Source
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type |
Description |
System.Int32 |
|
Overrides
|
Improve this Doc
View Source
GetTermsEnum(Terms, AttributeSource)
Declaration
protected override TermsEnum GetTermsEnum(Terms terms, AttributeSource atts)
Parameters
Returns
Overrides
|
Improve this Doc
View Source
SingleToEdits(Single, Int32)
Helper function to convert from deprecated "minimumSimilarity" fractions
to raw edit distances.
NOTE: this was floatToEdits() in Lucene
Declaration
public static int SingleToEdits(float minimumSimilarity, int termLen)
Parameters
Type |
Name |
Description |
System.Single |
minimumSimilarity |
Scaled similarity
|
System.Int32 |
termLen |
Length (in unicode codepoints) of the term.
|
Returns
Type |
Description |
System.Int32 |
Equivalent number of maxEdits
|
|
Improve this Doc
View Source
ToString(String)
Declaration
public override string ToString(string field)
Parameters
Type |
Name |
Description |
System.String |
field |
|
Returns
Type |
Description |
System.String |
|
Overrides