public class XAnalyzingSuggester extends org.apache .lucene .search .suggest .Lookup
This can result in powerful suggester functionality. For example, if you use an analyzer removing stop words, then the partial text "ghost chr..." could see the suggestion "The Ghost of Christmas Past". Note that position increments MUST NOT be preserved for this example to work, so you should call the constructor with preservePositionIncrements parameter set to false
If SynonymFilter is used to map wifi and wireless network to hotspot then the partial text "wirele..." could suggest "wifi router". Token normalization like stemmers, accent removal, etc., would allow suggestions to ignore such variations.
When two matching suggestions have the same weight, they are tie-broken by the analyzed form. If their analyzed form is the same then the order is undefined.
There are some limitations:
StopFilter, and the user will type "fast apple", but so far all they've typed is "fast a", again because the analyzer doesn't convey whether it's seen a token separator after the "a", StopFilter will remove that "a" causing far more matches than you'd expect. | Modifier and Type | Class and Description |
|---|---|
static class |
XAnalyzingSuggester
|
| Modifier and Type | Field and Description |
|---|---|
static int |
END_BYTE
Marks end of the analyzed input and start of dedup byte.
|
static int |
EXACT_FIRST
Include this flag in the options parameter to
#XAnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean,FST,boolean,int,int,int,int,int) to always return the exact match first, regardless of score.
|
static int |
HOLE_CHARACTER
|
static int |
PAYLOAD_SEP
|
static int |
PRESERVE_SEP
Include this flag in the options parameter to
#XAnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean,FST,boolean,int,int,int,int,int) to preserve token separators when matching.
|
static int |
SEP_LABEL
Represents the separation between tokens, if PRESERVE_SEP was specified
|
| Constructor and Description |
|---|
XAnalyzingSuggester(org
Calls
AnalyzingSuggester(analyzer, analyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1)
|
XAnalyzingSuggester(org
Calls
AnalyzingSuggester(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1)
|
XAnalyzingSuggester(org
Creates a new suggester.
|
| Modifier and Type | Method and Description |
|---|---|
void |
build(org
|
protected org |
convertAutomaton(org
|
static int |
decodeWeight(long encoded)
cost -> weight
|
static int |
encodeWeight(long value)
weight -> cost
|
Object |
get(CharSequence
Returns the weight associated with an input string, or null if it does not exist.
|
long |
getCount()
|
protected List |
getFullPrefixPaths(List
Returns all completion paths to initialize the search.
|
org |
getTokenStreamToAutomaton()
|
boolean |
load(org
|
boolean |
load(InputStream
|
List |
lookup(CharSequence
|
long |
ramBytesUsed()
Returns byte size of the underlying FST.
|
boolean |
store(org
|
boolean |
store(OutputStream
|
Set |
toFiniteStrings(org
|
Set |
toFiniteStrings(org
|
public static final int EXACT_FIRST
#XAnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean,FST,boolean,int,int,int,int,int) to always return the exact match first, regardless of score. This has no performance impact but could result in low-quality suggestions.
public static final int PRESERVE_SEP
#XAnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean,FST,boolean,int,int,int,int,int) to preserve token separators when matching.
public static final int SEP_LABEL
public static final int END_BYTE
public static final int PAYLOAD_SEP
public static final int HOLE_CHARACTER
public XAnalyzingSuggester(org.apache .lucene .analysis .Analyzer analyzer)
AnalyzingSuggester(analyzer, analyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1)
public XAnalyzingSuggester(org.apache .lucene .analysis .Analyzer indexAnalyzer, org .apache .lucene .analysis .Analyzer queryAnalyzer)
AnalyzingSuggester(indexAnalyzer, queryAnalyzer, EXACT_FIRST | PRESERVE_SEP, 256, -1)
public XAnalyzingSuggester(org.apache .lucene .analysis .Analyzer indexAnalyzer, org .apache .lucene .util .automaton .Automaton queryPrefix, org .apache .lucene .analysis .Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, boolean preservePositionIncrements, org .apache .lucene .util .fst .FST <org .apache .lucene .util .fst .PairOutputs .Pair <Long ,org .apache .lucene .util .BytesRef >> fst, boolean hasPayloads, int maxAnalyzedPathsForOneInput, int sepLabel, int payloadSep, int endByte, int holeCharacter)
indexAnalyzer - Analyzer that will be used for analyzing suggestions while building the index.
queryAnalyzer - Analyzer that will be used for analyzing query text during lookup
options - see
EXACT_FIRST,
PRESERVE_SEP
maxSurfaceFormsPerAnalyzedForm - Maximum number of surface forms to keep for a single analyzed form. When there are too many surface forms we discard the lowest weighted ones.
maxGraphExpansions - Maximum number of graph paths to expand from the analyzed form. Set this to -1 for no limit.
public long ramBytesUsed()
protected org.apache .lucene .util .automaton .Automaton convertAutomaton(org .apache .lucene .util .automaton .Automaton a)
public org.apache .lucene .analysis .TokenStreamToAutomaton getTokenStreamToAutomaton()
public void build(org.apache .lucene .search .suggest .InputIterator iterator) throws IOException
build in class
org.apache.lucene.search.suggest.Lookup
IOException
public boolean store(OutputStreamoutput) throws IOException
store in class
org.apache.lucene.search.suggest.Lookup
IOException
public long getCount()
public boolean load(InputStreaminput) throws IOException
load in class
org.apache.lucene.search.suggest.Lookup
IOException
public List<org .apache .lucene .search .suggest .Lookup .LookupResult > lookup(CharSequence key, Set <org .apache .lucene .util .BytesRef > contexts, boolean onlyMorePopular, int num)
public boolean store(org.apache .lucene .store .DataOutput output) throws IOException
store in class
org.apache.lucene.search.suggest.Lookup
IOException
public boolean load(org.apache .lucene .store .DataInput input) throws IOException
load in class
org.apache.lucene.search.suggest.Lookup
IOException
protected List<org .apache .lucene .search .suggest .analyzing .FSTUtil .Path <org .apache .lucene .util .fst .PairOutputs .Pair <Long ,org .apache .lucene .util .BytesRef >>> getFullPrefixPaths(List <org .apache .lucene .search .suggest .analyzing .FSTUtil .Path <org .apache .lucene .util .fst .PairOutputs .Pair <Long ,org .apache .lucene .util .BytesRef >>> prefixPaths, org .apache .lucene .util .automaton .Automaton lookupAutomaton, org .apache .lucene .util .fst .FST <org .apache .lucene .util .fst .PairOutputs .Pair <Long ,org .apache .lucene .util .BytesRef >> fst) throws IOException
IOException
public final Set<org .apache .lucene .util .IntsRef > toFiniteStrings(org .apache .lucene .util .BytesRef surfaceForm, org .apache .lucene .analysis .TokenStreamToAutomaton ts2a) throws IOException
IOException
public final Set<org .apache .lucene .util .IntsRef > toFiniteStrings(org .apache .lucene .analysis .TokenStreamToAutomaton ts2a, org .apache .lucene .analysis .TokenStream ts) throws IOException
IOException
public Objectget(CharSequence key)
public static int decodeWeight(long encoded)
public static int encodeWeight(long value)