org.apache.lucene.search
Class FuzzyQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.MultiTermQuery
-
- org.apache.lucene.search.FuzzyQuery
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class FuzzyQuery extends MultiTermQuery
Implements the fuzzy search query. The similiarity measurement is based on the Levenshtein (edit distance) algorithm.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static floatdefaultMinSimilaritystatic intdefaultPrefixLength
-
Constructor Summary
Constructors Constructor and Description FuzzyQuery(Term term)CallsFuzzyQuery(term, 0.5f, 0).FuzzyQuery(Term term, float minimumSimilarity)FuzzyQuery(Term term, float minimumSimilarity, int prefixLength)Create a new FuzzyQuery that will match terms with a similarity of at leastminimumSimilaritytoterm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object o)floatgetMinSimilarity()Returns the minimum similarity that is required for this query to match.intgetPrefixLength()Returns the non-fuzzy prefix length.inthashCode()Queryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.java.lang.StringtoString(java.lang.String field)Prints a user-readable version of this query.-
Methods inherited from class org.apache.lucene.search.MultiTermQuery
getTerm
-
Methods inherited from class org.apache.lucene.search.Query
clone, combine, extractTerms, getBoost, getSimilarity, mergeBooleanQueries, setBoost, toString, weight
-
-
-
-
Field Detail
-
defaultMinSimilarity
public static final float defaultMinSimilarity
- See Also:
- Constant Field Values
-
defaultPrefixLength
public static final int defaultPrefixLength
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FuzzyQuery
public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) throws java.lang.IllegalArgumentException
Create a new FuzzyQuery that will match terms with a similarity of at leastminimumSimilaritytoterm. If aprefixLength> 0 is specified, a common prefix of that length is also required.- Parameters:
term- the term to search forminimumSimilarity- a value between 0 and 1 to set the required similarity between the query term and the matching terms. For example, for aminimumSimilarityof0.5a 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 thanlength(term)*0.5prefixLength- length of common (non-fuzzy) prefix- Throws:
java.lang.IllegalArgumentException- if minimumSimilarity is >= 1 or < 0 or if prefixLength < 0
-
FuzzyQuery
public FuzzyQuery(Term term, float minimumSimilarity) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
FuzzyQuery
public FuzzyQuery(Term term)
CallsFuzzyQuery(term, 0.5f, 0).
-
-
Method Detail
-
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 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.
-
rewrite
public Query rewrite(IndexReader reader) throws java.io.IOException
Description copied from class:QueryExpert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.- Overrides:
rewritein classMultiTermQuery- Throws:
java.io.IOException
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:MultiTermQueryPrints a user-readable version of this query.- Overrides:
toStringin classMultiTermQuery
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classMultiTermQuery
-
hashCode
public int hashCode()
- Overrides:
hashCodein classMultiTermQuery
-
-
DataMelt 3.0 © DataMelt by jWork.ORG