public abstract class ReusableAnalyzerBase extends Analyzer
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).
| Modifier and Type | Class and Description |
|---|---|
static class |
ReusableAnalyzerBase.TokenStreamComponents
This class encapsulates the outer components of a token stream.
|
| Constructor and Description |
|---|
ReusableAnalyzerBase() |
| Modifier and Type | Method and Description |
|---|---|
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. |
close, getOffsetGap, getPositionIncrementGap, getPreviousTokenStream, setPreviousTokenStreamprotected abstract ReusableAnalyzerBase.TokenStreamComponents createComponents(String fieldName, Reader reader)
ReusableAnalyzerBase.TokenStreamComponents instance for this analyzer.fieldName - the name of the fields content passed to the
ReusableAnalyzerBase.TokenStreamComponents sink as a readerreader - the reader passed to the Tokenizer constructorReusableAnalyzerBase.TokenStreamComponents for this analyzer.public final TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException
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.reusableTokenStream in class AnalyzerfieldName - the name of the field the created TokenStream is used forreader - the reader the streams source reads fromIOExceptionpublic final TokenStream tokenStream(String fieldName, Reader reader)
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.tokenStream in class AnalyzerfieldName - the name of the field the created TokenStream is used forreader - the reader the streams source reads from