Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » analysis » [javadoc | source]
org.apache.lucene.analysis
public class: PerFieldAnalyzerWrapper [javadoc | source]
java.lang.Object
   org.apache.lucene.analysis.Analyzer
      org.apache.lucene.analysis.PerFieldAnalyzerWrapper

All Implemented Interfaces:
    Closeable

This analyzer is used to facilitate scenarios where different fields require different analysis techniques. Use #addAnalyzer 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.
Fields inherited from org.apache.lucene.analysis.Analyzer:
overridesTokenStreamMethod
Constructor:
 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<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 from org.apache.lucene.analysis.PerFieldAnalyzerWrapper Summary:
addAnalyzer,   getPositionIncrementGap,   reusableTokenStream,   toString,   tokenStream
Methods from org.apache.lucene.analysis.Analyzer:
close,   getOffsetGap,   getPositionIncrementGap,   getPreviousTokenStream,   reusableTokenStream,   setOverridesTokenStreamMethod,   setPreviousTokenStream,   tokenStream
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.lucene.analysis.PerFieldAnalyzerWrapper Detail:
 public  void addAnalyzer(String fieldName,
    Analyzer analyzer) 
    Defines an analyzer to use for the specified field.
 public int getPositionIncrementGap(String fieldName) 
    Return the positionIncrementGap from the analyzer assigned to fieldName
 public TokenStream reusableTokenStream(String fieldName,
    Reader reader) throws IOException 
 public String toString() 
 public TokenStream tokenStream(String fieldName,
    Reader reader)