public class AnalyzingInfixSuggester extends Lookup implements Closeable
This just uses an ordinary Lucene index. It
supports payloads, and records these as a
BinaryDocValues field. Matches are sorted only
by the suggest weight; it would be nice to support
blended score + weight sort in the future. This means
this suggester best applies when there is a strong
apriori ranking of all the suggestions.
Lookup.LookupPriorityQueue, Lookup.LookupResult| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MIN_PREFIX_CHARS
Default minimum number of leading characters before
PrefixQuery is used (4).
|
protected Analyzer |
indexAnalyzer
Analyzer used at index time
|
protected Analyzer |
queryAnalyzer
Analyzer used at search time
|
protected IndexSearcher |
searcher
IndexSearcher used for lookups. |
protected static String |
TEXT_FIELD_NAME
Field name used for the indexed text.
|
CHARSEQUENCE_COMPARATOR| Constructor and Description |
|---|
AnalyzingInfixSuggester(Version matchVersion,
File indexPath,
Analyzer analyzer)
Create a new instance, loading from a previously built
directory, if it exists.
|
AnalyzingInfixSuggester(Version matchVersion,
File indexPath,
Analyzer indexAnalyzer,
Analyzer queryAnalyzer,
int minPrefixChars)
Create a new instance, loading from a previously built
directory, if it exists.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addNonMatch(StringBuilder sb,
String text)
Called while highlighting a single result, to append a
non-matching chunk of text from the suggestion to the
provided fragments list.
|
protected void |
addPrefixMatch(StringBuilder sb,
String surface,
String analyzed,
String prefixToken)
Called while highlighting a single result, to append a
matched prefix token, to the provided fragments list.
|
protected void |
addWholeMatch(StringBuilder sb,
String surface,
String analyzed)
Called while highlighting a single result, to append
the whole matched token to the provided fragments list.
|
void |
build(InputIterator iter)
Builds up a new internal
Lookup representation based on the given InputIterator. |
void |
close() |
protected Query |
finishQuery(BooleanQuery in,
boolean allTermsRequired)
Subclass can override this to tweak the Query before
searching.
|
protected Directory |
getDirectory(File path)
Subclass can override to choose a specific
Directory implementation. |
protected IndexWriterConfig |
getIndexWriterConfig(Version matchVersion,
Analyzer indexAnalyzer)
Override this to customize index settings, e.g.
|
protected Query |
getLastTokenQuery(String token)
This is called if the last token isn't ended
(e.g.
|
protected Object |
highlight(String text,
Set<String> matchedTokens,
String prefixToken)
Override this method to customize the Object
representing a single highlighted suggestions; the
result is set on each
Lookup.LookupResult.highlightKey member. |
boolean |
load(InputStream out)
Discard current lookup data and load it from a previously saved copy.
|
List<Lookup.LookupResult> |
lookup(CharSequence key,
boolean onlyMorePopular,
int num)
Look up a key and return possible completion for this key.
|
List<Lookup.LookupResult> |
lookup(CharSequence key,
int num,
boolean allTermsRequired,
boolean doHighlight)
Retrieve suggestions, specifying whether all terms
must match (
allTermsRequired) and whether the hits
should be highlighted (doHighlight). |
long |
sizeInBytes()
Get the size of the underlying lookup implementation in memory
|
boolean |
store(OutputStream out)
Persist the constructed lookup data to a directory.
|
protected static final String TEXT_FIELD_NAME
protected final Analyzer queryAnalyzer
protected final Analyzer indexAnalyzer
protected IndexSearcher searcher
IndexSearcher used for lookups.public static final int DEFAULT_MIN_PREFIX_CHARS
public AnalyzingInfixSuggester(Version matchVersion, File indexPath, Analyzer analyzer) throws IOException
IOExceptionpublic AnalyzingInfixSuggester(Version matchVersion, File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars) throws IOException
minPrefixChars - Minimum number of leading characters
before PrefixQuery is used (default 4).
Prefixes shorter than this are indexed as character
ngrams (increasing index size but making lookups
faster).IOExceptionprotected IndexWriterConfig getIndexWriterConfig(Version matchVersion, Analyzer indexAnalyzer)
protected Directory getDirectory(File path) throws IOException
Directory implementation.IOExceptionpublic void build(InputIterator iter) throws IOException
LookupLookup representation based on the given InputIterator.
The implementation might re-sort the data internally.build in class LookupIOExceptionpublic List<Lookup.LookupResult> lookup(CharSequence key, boolean onlyMorePopular, int num)
Lookuplookup in class Lookupkey - lookup key. Depending on the implementation this may be
a prefix, misspelling, or even infix.onlyMorePopular - return only more popular resultsnum - maximum number of results to returnprotected Query getLastTokenQuery(String token) throws IOException
IOExceptionpublic List<Lookup.LookupResult> lookup(CharSequence key, int num, boolean allTermsRequired, boolean doHighlight)
allTermsRequired) and whether the hits
should be highlighted (doHighlight).protected Query finishQuery(BooleanQuery in, boolean allTermsRequired)
protected Object highlight(String text, Set<String> matchedTokens, String prefixToken) throws IOException
Lookup.LookupResult.highlightKey member.IOExceptionprotected void addNonMatch(StringBuilder sb, String text)
sb - The StringBuilder to append totext - The text chunk to addprotected void addWholeMatch(StringBuilder sb, String surface, String analyzed)
sb - The StringBuilder to append tosurface - The surface form (original) textanalyzed - The analyzed token corresponding to the surface form textprotected void addPrefixMatch(StringBuilder sb, String surface, String analyzed, String prefixToken)
sb - The StringBuilder to append tosurface - The fragment of the surface form
(indexed during build(org.apache.lucene.search.suggest.InputIterator), corresponding to
this matchanalyzed - The analyzed token that matchedprefixToken - The prefix of the token that matchedpublic boolean store(OutputStream out)
Lookupstore in class Lookupout - OutputStream to write the data to.public boolean load(InputStream out)
Lookupload in class Lookupout - the InputStream to load the lookup data.public void close()
throws IOException
close in interface CloseableIOExceptionpublic long sizeInBytes()
LookupsizeInBytes in class LookupCopyright © 2000-2013 Apache Software Foundation. All Rights Reserved.