Class AnalyzingInfixSuggester
- java.lang.Object
-
- org.apache.lucene.search.suggest.Lookup
-
- org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
BlendedInfixSuggester
public class AnalyzingInfixSuggester extends Lookup implements java.io.Closeable
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
Fields Modifier and Type Field Description static int
DEFAULT_MIN_PREFIX_CHARS
Default minimum number of leading characters before PrefixQuery is used (4).-
Fields inherited from class org.apache.lucene.search.suggest.Lookup
CHARSEQUENCE_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description AnalyzingInfixSuggester(Version matchVersion, java.io.File indexPath, Analyzer analyzer)
Create a new instance, loading from a previously built directory, if it exists.AnalyzingInfixSuggester(Version matchVersion, java.io.File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars)
Create a new instance, loading from a previously built directory, if it exists.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
build(InputIterator iter)
Builds up a new internalLookup
representation based on the givenInputIterator
.void
close()
long
getCount()
Get the number of entries the lookup was built withboolean
load(DataInput out)
Discard current lookup data and load it from a previously saved copy.java.util.List<Lookup.LookupResult>
lookup(java.lang.CharSequence key, boolean onlyMorePopular, int num)
Look up a key and return possible completion for this key.java.util.List<Lookup.LookupResult>
lookup(java.lang.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 memoryboolean
store(DataOutput in)
Persist the constructed lookup data to a directory.
-
-
-
Field Detail
-
DEFAULT_MIN_PREFIX_CHARS
public static final int DEFAULT_MIN_PREFIX_CHARS
Default minimum number of leading characters before PrefixQuery is used (4).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AnalyzingInfixSuggester
public AnalyzingInfixSuggester(Version matchVersion, java.io.File indexPath, Analyzer analyzer) throws java.io.IOException
Create a new instance, loading from a previously built directory, if it exists.- Throws:
java.io.IOException
-
AnalyzingInfixSuggester
public AnalyzingInfixSuggester(Version matchVersion, java.io.File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars) throws java.io.IOException
Create a new instance, loading from a previously built directory, if it exists.- Parameters:
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).- Throws:
java.io.IOException
-
-
Method Detail
-
build
public void build(InputIterator iter) throws java.io.IOException
Description copied from class:Lookup
Builds up a new internalLookup
representation based on the givenInputIterator
. The implementation might re-sort the data internally.
-
lookup
public java.util.List<Lookup.LookupResult> lookup(java.lang.CharSequence key, boolean onlyMorePopular, int num)
Description copied from class:Lookup
Look up a key and return possible completion for this key.- Specified by:
lookup
in classLookup
- Parameters:
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- Returns:
- a list of possible completions, with their relative weight (e.g. popularity)
-
lookup
public java.util.List<Lookup.LookupResult> lookup(java.lang.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
).
-
store
public boolean store(DataOutput in) throws java.io.IOException
Description copied from class:Lookup
Persist the constructed lookup data to a directory. Optional operation.- Specified by:
store
in classLookup
- Parameters:
in
-DataOutput
to write the data to.- Returns:
- true if successful, false if unsuccessful or not supported.
- Throws:
java.io.IOException
- when fatal IO error occurs.
-
load
public boolean load(DataInput out) throws java.io.IOException
Description copied from class:Lookup
Discard current lookup data and load it from a previously saved copy. Optional operation.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
sizeInBytes
public long sizeInBytes()
Description copied from class:Lookup
Get the size of the underlying lookup implementation in memory- Specified by:
sizeInBytes
in classLookup
- Returns:
- ram size of the lookup implementation in bytes
-
-