Class AnalyzingInfixSuggester
- java.lang.Object
-
- org.apache.lucene.search.suggest.Lookup
-
- org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
BlendedInfixSuggester
public class AnalyzingInfixSuggester extends Lookup implements 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, 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
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.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 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, File indexPath, Analyzer analyzer) throws IOException
Create a new instance, loading from a previously built directory, if it exists.- Throws:
IOException
-
AnalyzingInfixSuggester
public AnalyzingInfixSuggester(Version matchVersion, File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars) throws 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:
IOException
-
-
Method Detail
-
build
public void build(InputIterator iter) throws IOException
Description copied from class:Lookup
Builds up a new internalLookup
representation based on the givenInputIterator
. The implementation might re-sort the data internally.- Specified by:
build
in classLookup
- Throws:
IOException
-
lookup
public List<Lookup.LookupResult> lookup(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 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
).
-
store
public boolean store(DataOutput in) throws 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:
IOException
- when fatal IO error occurs.
-
load
public boolean load(DataInput out) throws IOException
Description copied from class:Lookup
Discard current lookup data and load it from a previously saved copy. Optional operation.- Specified by:
load
in classLookup
- Parameters:
out
- theDataInput
to load the lookup data.- Returns:
- true if completed successfully, false if unsuccessful or not supported.
- Throws:
IOException
- when fatal IO error occurs.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
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
-
-