|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.search.suggest.Lookup org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
public class AnalyzingInfixSuggester
Analyzes the input text and then suggests matches based on prefix matches to any tokens in the indexed text. This also highlights the tokens that match.
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.apache.lucene.search.suggest.Lookup |
---|
Lookup.LookupPriorityQueue, Lookup.LookupResult |
Field Summary | |
---|---|
static int |
DEFAULT_MIN_PREFIX_CHARS
Default minimum number of leading characters before PrefixQuery is used (4). |
protected IndexSearcher |
searcher
IndexSearcher used for lookups. |
protected static String |
TEXT_FIELD_NAME
Field name used for the indexed text. |
Fields inherited from class org.apache.lucene.search.suggest.Lookup |
---|
CHARSEQUENCE_COMPARATOR |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
protected void |
addPrefixMatch(StringBuilder sb,
String surface,
String analyzed,
String prefixToken)
Append a matched prefix token, to the provided StringBuilder . |
protected void |
addWholeMatch(StringBuilder sb,
String surface,
String analyzed)
Appends the whole matched token to the provided StringBuilder . |
void |
build(TermFreqIterator iter)
Builds up a new internal Lookup representation based on the given TermFreqIterator . |
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. |
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 ). |
boolean |
store(OutputStream out)
Persist the constructed lookup data to a directory. |
Methods inherited from class org.apache.lucene.search.suggest.Lookup |
---|
build |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String TEXT_FIELD_NAME
protected IndexSearcher searcher
IndexSearcher
used for lookups.
public static final int DEFAULT_MIN_PREFIX_CHARS
Constructor Detail |
---|
public AnalyzingInfixSuggester(Version matchVersion, File indexPath, Analyzer analyzer) throws IOException
IOException
public 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).
IOException
Method Detail |
---|
protected IndexWriterConfig getIndexWriterConfig(Version matchVersion, Analyzer indexAnalyzer)
protected Directory getDirectory(File path) throws IOException
Directory
implementation.
IOException
public void build(TermFreqIterator iter) throws IOException
Lookup
Lookup
representation based on the given TermFreqIterator
.
The implementation might re-sort the data internally.
build
in class Lookup
IOException
public List<Lookup.LookupResult> lookup(CharSequence key, 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.onlyMorePopular
- return only more popular resultsnum
- maximum number of results to return
protected Query getLastTokenQuery(String token) throws IOException
IOException
public 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 void addWholeMatch(StringBuilder sb, String surface, String analyzed)
StringBuilder
.
protected void addPrefixMatch(StringBuilder sb, String surface, String analyzed, String prefixToken)
StringBuilder
.
sb
- StringBuilder
to append tosurface
- The fragment of the surface form
(indexed during build(org.apache.lucene.search.spell.TermFreqIterator)
, corresponding to
this matchanalyzed
- The analyzed token that matchedprefixToken
- The prefix of the token that matchedpublic boolean store(OutputStream out)
Lookup
store
in class Lookup
out
- OutputStream
to write the data to.
public boolean load(InputStream out)
Lookup
load
in class Lookup
out
- the InputStream
to load the lookup data.
public void close() throws IOException
close
in interface Closeable
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |