FuzzyQuerypublic final class FuzzyQuery extends MultiTermQuery Implements the fuzzy search query. The similiarity measurement
is based on the Levenshtein (edit distance) algorithm. |
Fields Summary |
---|
public static final float | defaultMinSimilarity | private float | minimumSimilarity | private int | prefixLength |
Constructors Summary |
---|
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.
super(term);
if (minimumSimilarity > 1.0f)
throw new IllegalArgumentException("minimumSimilarity > 1");
else if (minimumSimilarity < 0.0f)
throw new IllegalArgumentException("minimumSimilarity < 0");
this.minimumSimilarity = minimumSimilarity;
if(prefixLength < 0)
throw new IllegalArgumentException("prefixLength < 0");
else if(prefixLength >= term.text().length())
throw new IllegalArgumentException("prefixLength >= term.text().length()");
this.prefixLength = prefixLength;
| public FuzzyQuery(Term term, float minimumSimilarity)Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.
this(term, minimumSimilarity, 0);
| public FuzzyQuery(Term term)Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.
this(term, defaultMinSimilarity, 0);
|
Methods Summary |
---|
protected org.apache.lucene.search.FilteredTermEnum | getEnum(org.apache.lucene.index.IndexReader reader)
return new FuzzyTermEnum(reader, getTerm(), minimumSimilarity, prefixLength);
| public float | getMinSimilarity()Returns the minimum similarity that is required for this query to match.
return minimumSimilarity;
| 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.
return prefixLength;
| public java.lang.String | toString(java.lang.String field)
return super.toString(field) + '~" + Float.toString(minimumSimilarity);
|
|