Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.analysis
Class PerFieldAnalyzerWrapper

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

    public class PerFieldAnalyzerWrapper

extends Analyzer

This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use `addAnalyzer(java.lang.String, org.apache.lucene.analysis.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.

Constructor Summary
`PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer)` Constructs with default analyzer.

Method Summary
`void` | `addAnalyzer(String fieldName, Analyzer analyzer)` Defines an analyzer to use for the specified 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.
`TokenStream` | `tokenStream(String fieldName, Reader reader)` Creates a TokenStream which tokenizes all the text in the provided Reader.
`String` | `toString()`

Methods inherited from class org.apache.lucene.analysis.Analyzer
`getPreviousTokenStream, setPreviousTokenStream`

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.

Method Detail

### addAnalyzer

    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

### tokenStream

    public TokenStream tokenStream(String fieldName,
                                   Reader reader)

  Description copied from class: `Analyzer`
  Creates a TokenStream which tokenizes all the text in the provided Reader. Default implementation forwards to tokenStream(Reader) for compatibility with older version. Override to allow Analyzer to choose strategy based on document and/or field. Must be able to handle null field name for backward compatibility.

  Specified by:
    `tokenStream` in class `Analyzer`

### reusableTokenStream

    public TokenStream reusableTokenStream(String fieldName,
                                           Reader reader)
                                    throws IOException

  Description copied from class: `Analyzer`
  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.

  Overrides:
    `reusableTokenStream` in class `Analyzer`
  Throws:
    `IOException`

### getPositionIncrementGap

    public int getPositionIncrementGap(String fieldName)

  Return the positionIncrementGap from the analyzer assigned to fieldName

  Overrides:
    `getPositionIncrementGap` in class `Analyzer`
  Parameters:
    `fieldName` - Fieldable name being indexed.
  Returns:
    position increment gap, added to the next token emitted from `Analyzer.tokenStream(String,Reader)`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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