Package org.apache.lucene.analysis
Class DelegatingAnalyzerWrapper
java.lang.Object
org.apache.lucene.analysis.Analyzer
org.apache.lucene.analysis.AnalyzerWrapper
org.apache.lucene.analysis.DelegatingAnalyzerWrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
An analyzer wrapper, that doesn't allow to wrap components or readers. By disallowing it, it
means that the thread local resources can be delegated to the delegate analyzer, and not also be
allocated on this analyzer. This wrapper class is the base class of all analyzers that just
delegate to another analyzer, e.g. per field name.
This solves the problem of per field analyzer wrapper, where it also maintains a thread local per field token stream components, while it can safely delegate those and not also hold these data structures, which can become expensive memory wise.
Please note: This analyzer uses a private Analyzer.ReuseStrategy
, which is
returned by Analyzer.getReuseStrategy()
. This strategy is used when delegating. If you wrap this
analyzer again and reuse this strategy, no delegation is done and the given fallback is used.
- Since:
- 4.10.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.analysis.Analyzer
Analyzer.ReuseStrategy, Analyzer.TokenStreamComponents
-
Field Summary
Fields inherited from class org.apache.lucene.analysis.Analyzer
GLOBAL_REUSE_STRATEGY, PER_FIELD_REUSE_STRATEGY
-
Constructor Summary
ModifierConstructorDescriptionprotected
DelegatingAnalyzerWrapper
(Analyzer.ReuseStrategy fallbackStrategy) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected final Analyzer.TokenStreamComponents
wrapComponents
(String fieldName, Analyzer.TokenStreamComponents components) Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components.protected final Reader
wrapReader
(String fieldName, Reader reader) Wraps / alters the given Reader.protected final Reader
wrapReaderForNormalization
(String fieldName, Reader reader) Wraps / alters the given Reader.protected final TokenStream
wrapTokenStreamForNormalization
(String fieldName, TokenStream in) Wraps / alters the given TokenStream for normalization purposes, taken from the wrapped Analyzer, to form new components.Methods inherited from class org.apache.lucene.analysis.AnalyzerWrapper
attributeFactory, createComponents, getOffsetGap, getPositionIncrementGap, getWrappedAnalyzer, initReader, initReaderForNormalization, normalize
Methods inherited from class org.apache.lucene.analysis.Analyzer
close, getReuseStrategy, normalize, tokenStream, tokenStream
-
Constructor Details
-
DelegatingAnalyzerWrapper
Constructor.- Parameters:
fallbackStrategy
- is the strategy to use if delegation is not possible This is to support the common pattern:new OtherWrapper(thisWrapper.getReuseStrategy())
-
-
Method Details
-
wrapComponents
protected final 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.
-
wrapTokenStreamForNormalization
Description copied from class:AnalyzerWrapper
Wraps / alters the given TokenStream for normalization purposes, 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 token stream are returned.- Overrides:
wrapTokenStreamForNormalization
in classAnalyzerWrapper
- Parameters:
fieldName
- Name of the field which is to be analyzedin
- TokenStream taken from the wrapped Analyzer- Returns:
- Wrapped / altered TokenStreamComponents.
-
wrapReader
Description copied from class:AnalyzerWrapper
Wraps / alters the given Reader. Through this method AnalyzerWrappers can implementAnalyzerWrapper.initReader(String, Reader)
. By default, the given reader is returned.- Overrides:
wrapReader
in classAnalyzerWrapper
- Parameters:
fieldName
- name of the field which is to be analyzedreader
- the reader to wrap- Returns:
- the wrapped reader
-
wrapReaderForNormalization
Description copied from class:AnalyzerWrapper
Wraps / alters the given Reader. Through this method AnalyzerWrappers can implementAnalyzerWrapper.initReaderForNormalization(String, Reader)
. By default, the given reader is returned.- Overrides:
wrapReaderForNormalization
in classAnalyzerWrapper
- Parameters:
fieldName
- name of the field which is to be analyzedreader
- the reader to wrap- Returns:
- the wrapped reader
-