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

      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

- - ### 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

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DelegatingAnalyzerWrapper(Analyzer.ReuseStrategy fallbackStrategy)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Analyzer.TokenStreamComponents` | `wrapComponents(String fieldName, Analyzer.TokenStreamComponents components)` Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components.
    `protected Reader` | `wrapReader(String fieldName, Reader reader)` Wraps / alters the given Reader.
    `protected Reader` | `wrapReaderForNormalization(String fieldName, Reader reader)` Wraps / alters the given Reader.
    `protected 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, getVersion, normalize, setVersion, tokenStream, tokenStream`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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 Detail

    - #### 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

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.