Class CompletionAnalyzer
java.lang.Object
org.apache.lucene.analysis.Analyzer
org.apache.lucene.analysis.AnalyzerWrapper
org.apache.lucene.search.suggest.document.CompletionAnalyzer
- All Implemented Interfaces:
Closeable
,AutoCloseable
Wraps an
Analyzer
to provide additional completion-only tuning
(e.g. preserving token separators, preserving position increments while converting a token stream
to an automaton)
Can be used to index SuggestField
and ContextSuggestField
and as a query
analyzer to PrefixCompletionQuery
amd FuzzyCompletionQuery
NOTE: In most cases, index and query analyzer should have same values for preservePositionIncrements()
and preserveSep()
- Since:
- 5.1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.analysis.Analyzer
Analyzer.ReuseStrategy, Analyzer.TokenStreamComponents
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Analyzer
(package private) static final int
Represent a hole character, inserted byTokenStreamToAutomaton
private final int
Sets the maximum number of graph expansions of a completion automatonprivate final boolean
Preserve position increments for tokens when converting to an automatonprivate final boolean
Preserve separation between tokens when converting to an automatonFields inherited from class org.apache.lucene.analysis.Analyzer
GLOBAL_REUSE_STRATEGY, PER_FIELD_REUSE_STRATEGY
-
Constructor Summary
ConstructorsConstructorDescriptionCompletionAnalyzer
(Analyzer analyzer) CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
preserving token separation, position increments and no limit on graph expansionsCompletionAnalyzer
(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements) CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
with no limit on graph expansionsCompletionAnalyzer
(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements, int maxGraphExpansions) Wraps an analyzer to convert its output token stream to an automatonCompletionAnalyzer
(Analyzer analyzer, int maxGraphExpansions) CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
preserving token separation and position increments -
Method Summary
Modifier and TypeMethodDescriptionprotected Analyzer
getWrappedAnalyzer
(String fieldName) Retrieves the wrapped Analyzer appropriate for analyzing the field with the given nameboolean
Returns true if position increments are preserved when converting the token stream to an automatonboolean
Returns true if separation between tokens are preserved when converting the token stream to an automatonprotected Analyzer.TokenStreamComponents
wrapComponents
(String fieldName, Analyzer.TokenStreamComponents components) Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components.Methods inherited from class org.apache.lucene.analysis.AnalyzerWrapper
attributeFactory, createComponents, getOffsetGap, getPositionIncrementGap, initReader, initReaderForNormalization, normalize, wrapReader, wrapReaderForNormalization, wrapTokenStreamForNormalization
Methods inherited from class org.apache.lucene.analysis.Analyzer
close, getReuseStrategy, normalize, tokenStream, tokenStream
-
Field Details
-
HOLE_CHARACTER
static final int HOLE_CHARACTERRepresent a hole character, inserted byTokenStreamToAutomaton
- See Also:
-
analyzer
-
preserveSep
private final boolean preserveSepPreserve separation between tokens when converting to an automatonDefaults to
true
-
preservePositionIncrements
private final boolean preservePositionIncrementsPreserve position increments for tokens when converting to an automatonDefaults to
true
-
maxGraphExpansions
private final int maxGraphExpansionsSets the maximum number of graph expansions of a completion automatonDefaults to
-1
(no limit)
-
-
Constructor Details
-
CompletionAnalyzer
public CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements, int maxGraphExpansions) Wraps an analyzer to convert its output token stream to an automaton- Parameters:
analyzer
- token stream to be converted to an automatonpreserveSep
- Preserve separation between tokens when converting to an automatonpreservePositionIncrements
- Preserve position increments for tokens when converting to an automatonmaxGraphExpansions
- Sets the maximum number of graph expansions of a completion automaton
-
CompletionAnalyzer
CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
preserving token separation, position increments and no limit on graph expansions -
CompletionAnalyzer
public CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements) CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
with no limit on graph expansions -
CompletionAnalyzer
CallsCompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)
preserving token separation and position increments
-
-
Method Details
-
preserveSep
public boolean preserveSep()Returns true if separation between tokens are preserved when converting the token stream to an automaton -
preservePositionIncrements
public boolean preservePositionIncrements()Returns true if position increments are preserved when converting the token stream to an automaton -
getWrappedAnalyzer
Description copied from class:AnalyzerWrapper
Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name- Specified by:
getWrappedAnalyzer
in classAnalyzerWrapper
- Parameters:
fieldName
- Name of the field which is to be analyzed- Returns:
- Analyzer for the field with the given name. Assumed to be non-null
-
wrapComponents
protected Analyzer.TokenStreamComponents wrapComponents(String fieldName, Analyzer.TokenStreamComponents components) Description copied from class:AnalyzerWrapper
Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components. It is through this method that new TokenFilters can be added by AnalyzerWrappers. By default, the given components are returned.- Overrides:
wrapComponents
in classAnalyzerWrapper
- Parameters:
fieldName
- Name of the field which is to be analyzedcomponents
- TokenStreamComponents taken from the wrapped Analyzer- Returns:
- Wrapped / altered TokenStreamComponents.
-