org.apache.lucene.analysis.miscellaneous

## Class PerFieldAnalyzerWrapper

- java.lang.Object
- - org.apache.lucene.analysis.Analyzer
  - - org.apache.lucene.analysis.AnalyzerWrapper
    - - org.apache.lucene.analysis.DelegatingAnalyzerWrapper
      - - org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public final class PerFieldAnalyzerWrapper
      extends DelegatingAnalyzerWrapper

  This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use the Map argument in `PerFieldAnalyzerWrapper(Analyzer, java.util.Map)` to add non-default analyzers for fields.

  Example usage:

       Map<String,Analyzer> analyzerPerField = new HashMap<>();
       analyzerPerField.put("firstname", new KeywordAnalyzer());
       analyzerPerField.put("lastname", new KeywordAnalyzer());

       PerFieldAnalyzerWrapper aWrapper =
         new PerFieldAnalyzerWrapper(new StandardAnalyzer(version), analyzerPerField);

  In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname", for which KeywordAnalyzer will be used.

  A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query parsing.

  Since:
    3.1

- - ### 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
    Constructor and Description
    `PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer)` Constructs with default analyzer.
    `PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer, Map<String,Analyzer> fieldAnalyzers)` Constructs with default analyzer and a map of analyzers to use for specific fields.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Analyzer` | `getWrappedAnalyzer(String fieldName)`
    `String` | `toString()`

    - ### Methods inherited from class org.apache.lucene.analysis.DelegatingAnalyzerWrapper

      `wrapComponents, wrapReader, wrapReaderForNormalization, wrapTokenStreamForNormalization`

    - ### Methods inherited from class org.apache.lucene.analysis.AnalyzerWrapper

      `attributeFactory, createComponents, getOffsetGap, getPositionIncrementGap, 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, wait, wait, wait`

- - ### Constructor Detail

    - #### PerFieldAnalyzerWrapper

          public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer)

      Constructs with default analyzer.
      Parameters:
        `defaultAnalyzer` - Any fields not specifically defined to use a different analyzer will use the one provided here.

    - #### PerFieldAnalyzerWrapper

          public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer,
                                         Map<String,Analyzer> fieldAnalyzers)

      Constructs with default analyzer and a map of analyzers to use for specific fields.
      Parameters:
        `defaultAnalyzer` - Any fields not specifically defined to use a different analyzer will use the one provided here.
        `fieldAnalyzers` - a Map (String field name to the Analyzer) to be used for those fields

  - ### Method Detail

    - #### getWrappedAnalyzer

          protected Analyzer getWrappedAnalyzer(String fieldName)

      Specified by:
        `getWrappedAnalyzer` in class `AnalyzerWrapper`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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