Module org.apache.lucene.suggest
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
-
public class FuzzyCompletionQuery extends PrefixCompletionQuery
ACompletionQuery
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"));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FuzzyCompletionQuery.FuzzyCompletionWeight
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_EDITS
The default maximum number of edits for fuzzy suggestions.static int
DEFAULT_MIN_FUZZY_LENGTH
The default minimum length of the key before any edits are allowed.static int
DEFAULT_NON_FUZZY_PREFIX
The default prefix length where edits are not allowed.static boolean
DEFAULT_TRANSPOSITIONS
The default transposition value passed toLevenshteinAutomata
static boolean
DEFAULT_UNICODE_AWARE
Measure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.private int
determinizeWorkLimit
private int
maxEdits
private int
minFuzzyLength
private int
nonFuzzyPrefix
private boolean
transpositions
private boolean
unicodeAware
-
Fields inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery
analyzer
-
-
Constructor Summary
Constructors Constructor Description FuzzyCompletionQuery(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
,unicodeAware
anddeterminizeWorkLimit
SeeDEFAULT_MAX_EDITS
,DEFAULT_TRANSPOSITIONS
,DEFAULT_NON_FUZZY_PREFIX
,DEFAULT_MIN_FUZZY_LENGTH
,DEFAULT_UNICODE_AWARE
andOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
for 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Weight
createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
Expert: Constructs an appropriate Weight implementation for this query.int
getDeterminizeWorkLimit()
Get the maximum effort to use determinizingint
getMaxEdits()
Get the maximum edit distance for fuzzy matchesint
getMinFuzzyLength()
Get the minimum length of a term considered for matchingint
getNonFuzzyPrefix()
Get the length of a prefix where no edits are permittedboolean
isTranspositions()
Return whether transpositions count as a single editboolean
isUnicodeAware()
Return true if lengths are measured in unicode code-points rather than bytesprivate Automaton
toLevenshteinAutomata(Automaton automaton, java.util.Set<IntsRef> refs)
java.lang.String
toString(java.lang.String field)
Prints a query to a string, withfield
assumed to be the default field and omitted.-
Methods inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery
equals, getAnalyzer, hashCode, visit
-
Methods inherited from class org.apache.lucene.search.suggest.document.CompletionQuery
getField, getFilter, getTerm, rewrite
-
Methods inherited from class org.apache.lucene.search.Query
classHash, rewrite, sameClassAs, toString
-
-
-
-
Field Detail
-
DEFAULT_UNICODE_AWARE
public static final boolean DEFAULT_UNICODE_AWARE
Measure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.- See Also:
- Constant Field Values
-
DEFAULT_MIN_FUZZY_LENGTH
public static final int DEFAULT_MIN_FUZZY_LENGTH
The default minimum length of the key before any edits are allowed.- See Also:
- Constant Field Values
-
DEFAULT_NON_FUZZY_PREFIX
public static final int DEFAULT_NON_FUZZY_PREFIX
The default prefix length where edits are not allowed.- See Also:
- Constant Field Values
-
DEFAULT_MAX_EDITS
public static final int DEFAULT_MAX_EDITS
The default maximum number of edits for fuzzy suggestions.- See Also:
- Constant Field Values
-
DEFAULT_TRANSPOSITIONS
public static final boolean DEFAULT_TRANSPOSITIONS
The default transposition value passed toLevenshteinAutomata
- See Also:
- Constant Field Values
-
maxEdits
private final int maxEdits
-
transpositions
private final boolean transpositions
-
nonFuzzyPrefix
private final int nonFuzzyPrefix
-
minFuzzyLength
private final int minFuzzyLength
-
unicodeAware
private final boolean unicodeAware
-
determinizeWorkLimit
private final int determinizeWorkLimit
-
-
Constructor Detail
-
FuzzyCompletionQuery
public FuzzyCompletionQuery(Analyzer analyzer, Term term)
CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer)
with no filter
-
FuzzyCompletionQuery
public FuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter)
CallsFuzzyCompletionQuery(Analyzer, Term, BitsProducer, int, boolean, int, int, boolean, int)
with defaults formaxEdits
,transpositions
,nonFuzzyPrefix
,minFuzzyLength
,unicodeAware
anddeterminizeWorkLimit
SeeDEFAULT_MAX_EDITS
,DEFAULT_TRANSPOSITIONS
,DEFAULT_NON_FUZZY_PREFIX
,DEFAULT_MIN_FUZZY_LENGTH
,DEFAULT_UNICODE_AWARE
andOperations.DEFAULT_DETERMINIZE_WORK_LIMIT
for 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 withanalyzer
filter
- used to query on a sub set of documentsmaxEdits
- maximum number of acceptable editstranspositions
- value passed toLevenshteinAutomata
nonFuzzyPrefix
- 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 Detail
-
createWeight
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws java.io.IOException
Description copied from class:Query
Expert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeight
in classPrefixCompletionQuery
scoreMode
- How the produced scorers will be consumed.boost
- The boost that is propagated by the parent queries.- Throws:
java.io.IOException
-
toLevenshteinAutomata
private Automaton toLevenshteinAutomata(Automaton automaton, java.util.Set<IntsRef> refs)
-
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
public java.lang.String toString(java.lang.String field)
Description copied from class:Query
Prints a query to a string, withfield
assumed to be the default field and omitted.- Overrides:
toString
in classCompletionQuery
-
-