org.apache.lucene.analysis
Class ReusableAnalyzerBase

java.lang.Object
  extended by org.apache.lucene.analysis.Analyzer
      extended by org.apache.lucene.analysis.ReusableAnalyzerBase
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
ChineseAnalyzer, CzechAnalyzer, DutchAnalyzer, KeywordAnalyzer, PatternAnalyzer, SimpleAnalyzer, StopwordAnalyzerBase, WhitespaceAnalyzer

public abstract class ReusableAnalyzerBase
extends Analyzer

An convenience subclass of Analyzer that makes it easy to implement TokenStream reuse.

ReusableAnalyzerBase is a simplification of Analyzer that supports easy reuse for the most common use-cases. Analyzers such as PerFieldAnalyzerWrapper that behave differently depending upon the field name need to subclass Analyzer directly instead.

To prevent consistency problems, this class does not allow subclasses to extend reusableTokenStream(String, Reader) or tokenStream(String, Reader) directly. Instead, subclasses must implement createComponents(String, Reader).


Nested Class Summary
static class ReusableAnalyzerBase.TokenStreamComponents
          This class encapsulates the outer components of a token stream.
 
Constructor Summary
ReusableAnalyzerBase()
           
 
Method Summary
protected abstract  ReusableAnalyzerBase.TokenStreamComponents createComponents(String fieldName, Reader reader)
          Creates a new ReusableAnalyzerBase.TokenStreamComponents instance for this analyzer.
protected  Reader initReader(Reader reader)
          Override this if you want to add a CharFilter chain.
 TokenStream reusableTokenStream(String fieldName, Reader reader)
          This method uses createComponents(String, Reader) to obtain an instance of ReusableAnalyzerBase.TokenStreamComponents.
 TokenStream tokenStream(String fieldName, Reader reader)
          This method uses createComponents(String, Reader) to obtain an instance of ReusableAnalyzerBase.TokenStreamComponents and returns the sink of the components.
 
Methods inherited from class org.apache.lucene.analysis.Analyzer
close, getOffsetGap, getPositionIncrementGap, getPreviousTokenStream, setPreviousTokenStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReusableAnalyzerBase

public ReusableAnalyzerBase()
Method Detail

createComponents

protected abstract ReusableAnalyzerBase.TokenStreamComponents createComponents(String fieldName,
                                                                               Reader reader)
Creates a new ReusableAnalyzerBase.TokenStreamComponents instance for this analyzer.

Parameters:
fieldName - the name of the fields content passed to the ReusableAnalyzerBase.TokenStreamComponents sink as a reader
reader - the reader passed to the Tokenizer constructor
Returns:
the ReusableAnalyzerBase.TokenStreamComponents for this analyzer.

reusableTokenStream

public final TokenStream reusableTokenStream(String fieldName,
                                             Reader reader)
                                      throws IOException
This method uses createComponents(String, Reader) to obtain an instance of ReusableAnalyzerBase.TokenStreamComponents. It returns the sink of the components and stores the components internally. Subsequent calls to this method will reuse the previously stored components if and only if the ReusableAnalyzerBase.TokenStreamComponents.reset(Reader) method returned true. Otherwise a new instance of ReusableAnalyzerBase.TokenStreamComponents is created.

Overrides:
reusableTokenStream in class Analyzer
Parameters:
fieldName - the name of the field the created TokenStream is used for
reader - the reader the streams source reads from
Throws:
IOException

tokenStream

public final TokenStream tokenStream(String fieldName,
                                     Reader reader)
This method uses createComponents(String, Reader) to obtain an instance of ReusableAnalyzerBase.TokenStreamComponents and returns the sink of the components. Each calls to this method will create a new instance of ReusableAnalyzerBase.TokenStreamComponents. Created TokenStream instances are never reused.

Specified by:
tokenStream in class Analyzer
Parameters:
fieldName - the name of the field the created TokenStream is used for
reader - the reader the streams source reads from

initReader

protected Reader initReader(Reader reader)
Override this if you want to add a CharFilter chain.