Class DelegatingAnalyzerWrapper

All Implemented Interfaces:
Closeable, AutoCloseable

public abstract class DelegatingAnalyzerWrapper extends AnalyzerWrapper
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
  • Constructor Details

    • DelegatingAnalyzerWrapper

      protected DelegatingAnalyzerWrapper(Analyzer.ReuseStrategy fallbackStrategy)
      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 class AnalyzerWrapper
      Parameters:
      fieldName - Name of the field which is to be analyzed
      components - TokenStreamComponents taken from the wrapped Analyzer
      Returns:
      Wrapped / altered TokenStreamComponents.
    • wrapTokenStreamForNormalization

      protected final TokenStream wrapTokenStreamForNormalization(String fieldName, TokenStream in)
      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 class AnalyzerWrapper
      Parameters:
      fieldName - Name of the field which is to be analyzed
      in - TokenStream taken from the wrapped Analyzer
      Returns:
      Wrapped / altered TokenStreamComponents.
    • wrapReader

      protected final Reader wrapReader(String fieldName, Reader reader)
      Description copied from class: AnalyzerWrapper
      Wraps / alters the given Reader. Through this method AnalyzerWrappers can implement AnalyzerWrapper.initReader(String, Reader). By default, the given reader is returned.
      Overrides:
      wrapReader in class AnalyzerWrapper
      Parameters:
      fieldName - name of the field which is to be analyzed
      reader - the reader to wrap
      Returns:
      the wrapped reader
    • wrapReaderForNormalization

      protected final Reader wrapReaderForNormalization(String fieldName, Reader reader)
      Description copied from class: AnalyzerWrapper
      Wraps / alters the given Reader. Through this method AnalyzerWrappers can implement AnalyzerWrapper.initReaderForNormalization(String, Reader). By default, the given reader is returned.
      Overrides:
      wrapReaderForNormalization in class AnalyzerWrapper
      Parameters:
      fieldName - name of the field which is to be analyzed
      reader - the reader to wrap
      Returns:
      the wrapped reader