## org.apache.lucene.analysis
Class AnalyzerWrapper

    java.lang.Object
      org.apache.lucene.analysis.Analyzer
          org.apache.lucene.analysis.AnalyzerWrapper

All Implemented Interfaces:
  Closeable

    public abstract class AnalyzerWrapper

extends Analyzer

Extension to `Analyzer` suitable for Analyzers which wrap other Analyzers.

`getWrappedAnalyzer(String)` allows the Analyzer to wrap multiple Analyzers which are selected on a per field basis.

`wrapComponents(String, Analyzer.TokenStreamComponents)` allows the TokenStreamComponents of the wrapped Analyzer to then be wrapped (such as adding a new `TokenFilter` to form new TokenStreamComponents.

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.lucene.analysis.Analyzer
`Analyzer.GlobalReuseStrategy, Analyzer.PerFieldReuseStrategy, Analyzer.ReuseStrategy, Analyzer.TokenStreamComponents`

Constructor Summary
`protected` `AnalyzerWrapper()` Creates a new AnalyzerWrapper.

Method Summary
`protected Analyzer.TokenStreamComponents` `createComponents(String fieldName, Reader aReader)` Creates a new `Analyzer.TokenStreamComponents` instance for this analyzer.
`int` `getOffsetGap(String fieldName)` Just like `Analyzer.getPositionIncrementGap(java.lang.String)`, except for Token offsets instead.
`int` `getPositionIncrementGap(String fieldName)` Invoked before indexing a IndexableField instance if terms have already been added to that field.
`protected abstract Analyzer` `getWrappedAnalyzer(String fieldName)` Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name
`Reader` `initReader(String fieldName, Reader reader)` Override this if you want to add a CharFilter chain.
`protected abstract 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.Analyzer
`close, tokenStream, tokenStream`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AnalyzerWrapper

    protected AnalyzerWrapper()

  Creates a new AnalyzerWrapper. Since the `Analyzer.ReuseStrategy` of the wrapped Analyzers are unknown, `Analyzer.PerFieldReuseStrategy` is assumed

Method Detail

### getWrappedAnalyzer

    protected abstract Analyzer getWrappedAnalyzer(String fieldName)

  Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name

  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 abstract Analyzer.TokenStreamComponents wrapComponents(String fieldName,
                                                                     Analyzer.TokenStreamComponents components)

  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.

  Parameters:
    `fieldName` - Name of the field which is to be analyzed
    `components` - TokenStreamComponents taken from the wrapped Analyzer
  Returns:
    Wrapped / altered TokenStreamComponents.

### createComponents

    protected final Analyzer.TokenStreamComponents createComponents(String fieldName,
                                                                    Reader aReader)

  Description copied from class: `Analyzer`
  Creates a new `Analyzer.TokenStreamComponents` instance for this analyzer.

  Specified by:
    `createComponents` in class `Analyzer`
  Parameters:
    `fieldName` - the name of the fields content passed to the `Analyzer.TokenStreamComponents` sink as a reader
    `aReader` - the reader passed to the `Tokenizer` constructor
  Returns:
    the `Analyzer.TokenStreamComponents` for this analyzer.

### getPositionIncrementGap

    public final int getPositionIncrementGap(String fieldName)

  Description copied from class: `Analyzer`
  Invoked before indexing a IndexableField instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between IndexbleField instances using the same field name. The default value position increment gap is 0. With a 0 position increment gap and the typical default token position increment of 1, all terms in a field, including across IndexableField instances, are in successive positions, allowing exact PhraseQuery matches, for instance, across IndexableField instance boundaries.

  Overrides:
    `getPositionIncrementGap` in class `Analyzer`
  Parameters:
    `fieldName` - IndexableField name being indexed.
  Returns:
    position increment gap, added to the next token emitted from `Analyzer.tokenStream(String,Reader)`. This value must be `>= 0`.

### getOffsetGap

    public final int getOffsetGap(String fieldName)

  Description copied from class: `Analyzer`
  Just like `Analyzer.getPositionIncrementGap(java.lang.String)`, except for Token offsets instead. By default this returns 1. This method is only called if the field produced at least one token for indexing.

  Overrides:
    `getOffsetGap` in class `Analyzer`
  Parameters:
    `fieldName` - the field just indexed
  Returns:
    offset gap, added to the next token emitted from `Analyzer.tokenStream(String,Reader)`. This value must be `>= 0`.

### initReader

    public final Reader initReader(String fieldName,
                                   Reader reader)

  Description copied from class: `Analyzer`
  Override this if you want to add a CharFilter chain.

  The default implementation returns `reader` unchanged.

  Overrides:
    `initReader` in class `Analyzer`
  Parameters:
    `fieldName` - IndexableField name being indexed
    `reader` - original Reader
  Returns:
    reader, optionally decorated with CharFilter(s)

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