Class FuzzyCompletionQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.suggest.document.CompletionQuery
org.apache.lucene.search.suggest.document.PrefixCompletionQuery
org.apache.lucene.search.suggest.document.FuzzyCompletionQuery
A
CompletionQuery that match documents containing terms within an edit distance of the
specified prefix.
This query boost documents relative to how similar the indexed terms are to the provided prefix.
Example usage of querying an analyzed prefix within an edit distance of 1 of 'subg' against a field 'suggest_field' is as follows:
CompletionQuery query = new FuzzyCompletionQuery(analyzer, new Term("suggest_field", "subg"));
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default maximum number of edits for fuzzy suggestions.static final intThe default minimum length of the key before any edits are allowed.static final intThe default prefix length where edits are not allowed.static final booleanThe default transposition value passed toLevenshteinAutomatastatic final booleanMeasure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.Fields inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery
analyzer -
Constructor Summary
ConstructorsConstructorDescriptionFuzzyCompletionQuery(Analyzer analyzer, Term term) CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer)with no filterFuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter) CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer, int, boolean, int, int, boolean, int)with defaults formaxEdits,transpositions,nonFuzzyPrefix,minFuzzyLength,unicodeAwareanddeterminizeWorkLimitSeeDEFAULT_MAX_EDITS,DEFAULT_TRANSPOSITIONS,DEFAULT_NON_FUZZY_PREFIX,DEFAULT_MIN_FUZZY_LENGTH,DEFAULT_UNICODE_AWAREandOperations.DEFAULT_DETERMINIZE_WORK_LIMITfor defaultsFuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter, int maxEdits, boolean transpositions, int nonFuzzyPrefix, int minFuzzyLength, boolean unicodeAware, int determinizeWorkLimit) Constructs an analyzed fuzzy prefix completion query -
Method Summary
Modifier and TypeMethodDescriptioncreateWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) intGet the maximum effort to use determinizingintGet the maximum edit distance for fuzzy matchesintGet the minimum length of a term considered for matchingintGet the length of a prefix where no edits are permittedbooleanReturn whether transpositions count as a single editbooleanReturn true if lengths are measured in unicode code-points rather than bytesMethods inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery
equals, getAnalyzer, hashCode, visitMethods inherited from class org.apache.lucene.search.suggest.document.CompletionQuery
getField, getFilter, getTerm, rewriteMethods inherited from class org.apache.lucene.search.Query
classHash, sameClassAs, toString
-
Field Details
-
DEFAULT_UNICODE_AWARE
public static final boolean DEFAULT_UNICODE_AWAREMeasure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.- See Also:
-
DEFAULT_MIN_FUZZY_LENGTH
public static final int DEFAULT_MIN_FUZZY_LENGTHThe default minimum length of the key before any edits are allowed.- See Also:
-
DEFAULT_NON_FUZZY_PREFIX
public static final int DEFAULT_NON_FUZZY_PREFIXThe default prefix length where edits are not allowed.- See Also:
-
DEFAULT_MAX_EDITS
public static final int DEFAULT_MAX_EDITSThe default maximum number of edits for fuzzy suggestions.- See Also:
-
DEFAULT_TRANSPOSITIONS
public static final boolean DEFAULT_TRANSPOSITIONSThe default transposition value passed toLevenshteinAutomata- See Also:
-
-
Constructor Details
-
FuzzyCompletionQuery
CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer)with no filter -
FuzzyCompletionQuery
CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer, int, boolean, int, int, boolean, int)with defaults formaxEdits,transpositions,nonFuzzyPrefix,minFuzzyLength,unicodeAwareanddeterminizeWorkLimitSeeDEFAULT_MAX_EDITS,DEFAULT_TRANSPOSITIONS,DEFAULT_NON_FUZZY_PREFIX,DEFAULT_MIN_FUZZY_LENGTH,DEFAULT_UNICODE_AWAREandOperations.DEFAULT_DETERMINIZE_WORK_LIMITfor defaults -
FuzzyCompletionQuery
public FuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter, int maxEdits, boolean transpositions, int nonFuzzyPrefix, int minFuzzyLength, boolean unicodeAware, int determinizeWorkLimit) Constructs an analyzed fuzzy prefix completion query- Parameters:
analyzer- used to analyze the providedTerm.text()term- query is run againstTerm.field()andTerm.text()is analyzed withanalyzerfilter- used to query on a sub set of documentsmaxEdits- maximum number of acceptable editstranspositions- value passed toLevenshteinAutomatanonFuzzyPrefix- prefix length where edits are not allowedminFuzzyLength- minimum prefix length before any edits are allowedunicodeAware- treat prefix as unicode rather than bytesdeterminizeWorkLimit- maximum effort allowed to determinize theLevenshteinAutomata
-
-
Method Details
-
createWeight
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException - Overrides:
createWeightin classPrefixCompletionQuery- Throws:
IOException
-
getMaxEdits
public int getMaxEdits()Get the maximum edit distance for fuzzy matches -
isTranspositions
public boolean isTranspositions()Return whether transpositions count as a single edit -
getNonFuzzyPrefix
public int getNonFuzzyPrefix()Get the length of a prefix where no edits are permitted -
getMinFuzzyLength
public int getMinFuzzyLength()Get the minimum length of a term considered for matching -
isUnicodeAware
public boolean isUnicodeAware()Return true if lengths are measured in unicode code-points rather than bytes -
getDeterminizeWorkLimit
public int getDeterminizeWorkLimit()Get the maximum effort to use determinizing -
toString
- Overrides:
toStringin classCompletionQuery
-