org.apache.lucene.search

Class FuzzyQuery

public final class FuzzyQuery extends MultiTermQuery

Implements the fuzzy search query. The similiarity measurement is based on the Levenshtein (edit distance) algorithm.
Field Summary
static floatdefaultMinSimilarity
Constructor Summary
FuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
Create a new FuzzyQuery that will match terms with a similarity of at least minimumSimilarity to term.
FuzzyQuery(Term term, float minimumSimilarity)
Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.
FuzzyQuery(Term term)
Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.
Method Summary
protected FilteredTermEnumgetEnum(IndexReader reader)
floatgetMinSimilarity()
Returns the minimum similarity that is required for this query to match.
intgetPrefixLength()
Returns the prefix length, i.e. 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.
StringtoString(String field)

Field Detail

defaultMinSimilarity

public static final float defaultMinSimilarity

Constructor Detail

FuzzyQuery

public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
Create a new FuzzyQuery that will match terms with a similarity of at least minimumSimilarity to term. If a prefixLength > 0 is specified, a common prefix of that length is also required.

Parameters: term the term to search for minimumSimilarity a value between 0 and 1 to set the required similarity between the query term and the matching terms. For example, for a minimumSimilarity of 0.5 a term of the same length as the query term is considered similar to the query term if the edit distance between both terms is less than length(term)*0.5 prefixLength length of common (non-fuzzy) prefix

Throws: IllegalArgumentException if minimumSimilarity is > 1 or < 0 or if prefixLength < 0 or > term.text().length().

FuzzyQuery

public FuzzyQuery(Term term, float minimumSimilarity)
Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.

FuzzyQuery

public FuzzyQuery(Term term)
Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.

Method Detail

getEnum

protected FilteredTermEnum getEnum(IndexReader reader)

getMinSimilarity

public float getMinSimilarity()
Returns the minimum similarity that is required for this query to match.

Returns: float value between 0.0 and 1.0

getPrefixLength

public int getPrefixLength()
Returns the prefix length, i.e. 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.

toString

public String toString(String field)
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.