public class AnalyzingSuggester extends 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.
Lookup.LookupPriorityQueue, Lookup.LookupResult
Modifier and Type | Field and Description |
---|---|
static int |
EXACT_FIRST
Include this flag in the options parameter to
AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean) to always
return the exact match first, regardless of score. |
static int |
PRESERVE_SEP
Include this flag in the options parameter to
AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean) to preserve
token separators when matching. |
CHARSEQUENCE_COMPARATOR
Constructor and Description |
---|
AnalyzingSuggester(Analyzer analyzer)
|
AnalyzingSuggester(Analyzer indexAnalyzer,
Analyzer queryAnalyzer)
|
AnalyzingSuggester(Analyzer indexAnalyzer,
Analyzer queryAnalyzer,
int options,
int maxSurfaceFormsPerAnalyzedForm,
int maxGraphExpansions,
boolean preservePositionIncrements)
Creates a new suggester.
|
Modifier and Type | Method and Description |
---|---|
void |
build(InputIterator iterator)
Builds up a new internal
Lookup representation based on the given InputIterator . |
protected Automaton |
convertAutomaton(Automaton a)
Used by subclass to change the lookup automaton, if
necessary.
|
Object |
get(CharSequence key)
Returns the weight associated with an input string,
or null if it does not exist.
|
Collection<Accountable> |
getChildResources()
Returns nested resources of this class.
|
long |
getCount()
Get the number of entries the lookup was built with
|
protected List<FSTUtil.Path<PairOutputs.Pair<Long,BytesRef>>> |
getFullPrefixPaths(List<FSTUtil.Path<PairOutputs.Pair<Long,BytesRef>>> prefixPaths,
Automaton lookupAutomaton,
FST<PairOutputs.Pair<Long,BytesRef>> fst)
Returns all prefix paths to initialize the search.
|
boolean |
load(DataInput input)
Discard current lookup data and load it from a previously saved copy.
|
List<Lookup.LookupResult> |
lookup(CharSequence key,
Set<BytesRef> contexts,
boolean onlyMorePopular,
int num)
Look up a key and return possible completion for this key.
|
long |
ramBytesUsed()
Returns byte size of the underlying FST.
|
boolean |
store(DataOutput output)
Persist the constructed lookup data to a directory.
|
public static final int EXACT_FIRST
AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean)
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
AnalyzingSuggester(Analyzer,Analyzer,int,int,int,boolean)
to preserve
token separators when matching.public AnalyzingSuggester(Analyzer analyzer)
public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, boolean preservePositionIncrements)
indexAnalyzer
- Analyzer that will be used for
analyzing suggestions while building the index.queryAnalyzer
- Analyzer that will be used for
analyzing query text during lookupoptions
- 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.preservePositionIncrements
- Whether position holes
should appear in the automatapublic long ramBytesUsed()
public Collection<Accountable> getChildResources()
Lookup
getChildResources
in interface Accountable
getChildResources
in class Lookup
Accountables
protected Automaton convertAutomaton(Automaton a)
public void build(InputIterator iterator) throws IOException
Lookup
Lookup
representation based on the given InputIterator
.
The implementation might re-sort the data internally.build
in class Lookup
IOException
public boolean store(DataOutput output) throws IOException
Lookup
store
in class Lookup
output
- DataOutput
to write the data to.IOException
- when fatal IO error occurs.public boolean load(DataInput input) throws IOException
Lookup
load
in class Lookup
input
- the DataInput
to load the lookup data.IOException
- when fatal IO error occurs.public List<Lookup.LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num)
Lookup
lookup
in class Lookup
key
- lookup key. Depending on the implementation this may be
a prefix, misspelling, or even infix.contexts
- contexts to filter the lookup by, or null if all contexts are allowed; if the suggestion contains any of the contexts, it's a matchonlyMorePopular
- return only more popular resultsnum
- maximum number of results to returnpublic long getCount()
Lookup
protected List<FSTUtil.Path<PairOutputs.Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<PairOutputs.Pair<Long,BytesRef>>> prefixPaths, Automaton lookupAutomaton, FST<PairOutputs.Pair<Long,BytesRef>> fst) throws IOException
IOException
public Object get(CharSequence key)
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.