public class

PerFieldAnalyzerWrapper

extends Analyzer
java.lang.Object
   ↳ org.apache.lucene.analysis.Analyzer
     ↳ org.apache.lucene.analysis.PerFieldAnalyzerWrapper

Class Overview

This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use addAnalyzer(String, Analyzer) to add a non-default analyzer on a field name basis.

Example usage:

   PerFieldAnalyzerWrapper aWrapper =
      new PerFieldAnalyzerWrapper(new StandardAnalyzer());
   aWrapper.addAnalyzer("firstname", new KeywordAnalyzer());
   aWrapper.addAnalyzer("lastname", new KeywordAnalyzer());
 

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.

Summary

[Expand]
Inherited Fields
From class org.apache.lucene.analysis.Analyzer
Public Constructors
PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer)
Constructs with default analyzer.
PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer, Map<StringAnalyzer> fieldAnalyzers)
Constructs with default analyzer and a map of analyzers to use for specific fields.
Public Methods
void addAnalyzer(String fieldName, Analyzer analyzer)
Defines an analyzer to use for the specified field.
int getOffsetGap(Fieldable field)
Return the offsetGap from the analyzer assigned to field
int getPositionIncrementGap(String fieldName)
Return the positionIncrementGap from the analyzer assigned to fieldName
TokenStream reusableTokenStream(String fieldName, Reader reader)
Creates a TokenStream that is allowed to be re-used from the previous time that the same thread called this method.
String toString()
TokenStream tokenStream(String fieldName, Reader reader)
Creates a TokenStream which tokenizes all the text in the provided Reader.
[Expand]
Inherited Methods
From class org.apache.lucene.analysis.Analyzer
From class java.lang.Object
From interface java.io.Closeable

Public Constructors

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.

public PerFieldAnalyzerWrapper (Analyzer defaultAnalyzer, Map<StringAnalyzer> 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

Public Methods

public void addAnalyzer (String fieldName, Analyzer analyzer)

Defines an analyzer to use for the specified field.

Parameters
fieldName field name requiring a non-default analyzer
analyzer non-default analyzer to use for field

public int getOffsetGap (Fieldable field)

Return the offsetGap from the analyzer assigned to field

Parameters
field the field just indexed
Returns

public int getPositionIncrementGap (String fieldName)

Return the positionIncrementGap from the analyzer assigned to fieldName

Parameters
fieldName Fieldable name being indexed.
Returns

public TokenStream reusableTokenStream (String fieldName, Reader reader)

Creates a TokenStream that is allowed to be re-used from the previous time that the same thread called this method. Callers that do not need to use more than one TokenStream at the same time from this analyzer should use this method for better performance.

Throws
IOException

public String toString ()

public TokenStream tokenStream (String fieldName, Reader reader)

Creates a TokenStream which tokenizes all the text in the provided Reader. Must be able to handle null field name for backward compatibility.