|
|||||||||
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 Analyzer |
indexAnalyzer
Analyzer used at index time |
protected BinaryDocValues |
payloadsDV
DocValuesField holding the payloads; null if payloads were not indexed. |
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. |
protected BinaryDocValues |
textDV
DocValuesField holding each suggestion's text. |
protected NumericDocValues |
weightsDV
DocValuesField holding each suggestion's weight. |
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 |
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 List<Lookup.LookupResult> |
createResults(TopDocs hits,
int num,
CharSequence charSequence,
boolean doHighlight,
Set<String> matchedTokens,
String prefixToken)
Create the results based on the search hits. |
protected Query |
finishQuery(BooleanQuery in,
boolean allTermsRequired)
Subclass can override this to tweak the Query before searching. |
long |
getCount()
Get the number of entries the lookup was built with |
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 FieldType |
getTextFieldType()
Subclass can override this method to change the field type of the text field 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(DataInput 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(DataOutput in)
Persist the constructed lookup data to a directory. |
Methods inherited from class org.apache.lucene.search.suggest.Lookup |
---|
build, load, store |
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 final Analyzer queryAnalyzer
protected final Analyzer indexAnalyzer
protected IndexSearcher searcher
IndexSearcher
used for lookups.
protected BinaryDocValues payloadsDV
protected BinaryDocValues textDV
protected NumericDocValues weightsDV
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(InputIterator iter) throws IOException
Lookup
Lookup
representation based on the given InputIterator
.
The implementation might re-sort the data internally.
build
in class Lookup
IOException
protected FieldType getTextFieldType()
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 List<Lookup.LookupResult> createResults(TopDocs hits, int num, CharSequence charSequence, boolean doHighlight, Set<String> matchedTokens, String prefixToken) throws IOException
IOException
- If there are problems reading fields from the underlying Lucene index.protected Query finishQuery(BooleanQuery in, boolean allTermsRequired)
protected Object highlight(String text, Set<String> matchedTokens, String prefixToken) throws IOException
Lookup.LookupResult.highlightKey
member.
IOException
protected 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(DataOutput in) throws IOException
Lookup
store
in class Lookup
in
- DataOutput
to write the data to.
IOException
- when fatal IO error occurs.public boolean load(DataInput out) throws IOException
Lookup
load
in class Lookup
out
- the DataInput
to load the lookup data.
IOException
- when fatal IO error occurs.public void close() throws IOException
close
in interface Closeable
IOException
public long sizeInBytes()
Lookup
sizeInBytes
in class Lookup
public long getCount()
Lookup
getCount
in class Lookup
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |