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
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
FieldsModifier and TypeFieldDescriptionstatic final intDefault minimum number of leading characters before PrefixQuery is used (4).Fields inherited from class org.apache.lucene.search.suggest.Lookup
CHARSEQUENCE_COMPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionAnalyzingInfixSuggester(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
Modifier and TypeMethodDescriptionvoidbuild(InputIterator iter) Builds up a new internalLookuprepresentation based on the givenInputIterator.voidclose()longgetCount()Get the number of entries the lookup was built withbooleanDiscard current lookup data and load it from a previously saved copy.lookup(CharSequence key, boolean onlyMorePopular, int num) Look up a key and return possible completion for this key.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).longGet the size of the underlying lookup implementation in memorybooleanstore(DataOutput in) Persist the constructed lookup data to a directory.
-
Field Details
-
DEFAULT_MIN_PREFIX_CHARS
public static final int DEFAULT_MIN_PREFIX_CHARSDefault minimum number of leading characters before PrefixQuery is used (4).- See Also:
-
-
Constructor Details
-
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 Details
-
build
Description copied from class:LookupBuilds up a new internalLookuprepresentation based on the givenInputIterator. The implementation might re-sort the data internally.- Specified by:
buildin classLookup- Throws:
IOException
-
lookup
Description copied from class:LookupLook up a key and return possible completion for this key.- Specified by:
lookupin 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
Description copied from class:LookupPersist the constructed lookup data to a directory. Optional operation.- Specified by:
storein classLookup- Parameters:
in-DataOutputto write the data to.- Returns:
- true if successful, false if unsuccessful or not supported.
- Throws:
IOException- when fatal IO error occurs.
-
load
Description copied from class:LookupDiscard current lookup data and load it from a previously saved copy. Optional operation.- Specified by:
loadin classLookup- Parameters:
out- theDataInputto load the lookup data.- Returns:
- true if completed successfully, false if unsuccessful or not supported.
- Throws:
IOException- when fatal IO error occurs.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
sizeInBytes
public long sizeInBytes()Description copied from class:LookupGet the size of the underlying lookup implementation in memory- Specified by:
sizeInBytesin classLookup- Returns:
- ram size of the lookup implementation in bytes
-
getCount
public long getCount()Description copied from class:LookupGet the number of entries the lookup was built with
-