Class AnalyzerWrapper
Extension to Analyzer suitable for Analyzers which wrap other Analyzers.
GetWrappedAnalyzer(string) allows the Analyzer to wrap multiple Analyzers which are selected on a per field basis. WrapComponents(string, TokenStreamComponents) allows the TokenStreamComponents of the wrapped Analyzer to then be wrapped (such as adding a new TokenFilter to form new TokenStreamComponents).Implements
Inherited Members
Namespace: Lucene.Net.Analysis
Assembly: Lucene.Net.dll
Syntax
public abstract class AnalyzerWrapper : Analyzer, IDisposable
Constructors
AnalyzerWrapper()
Creates a new AnalyzerWrapper. Since the ReuseStrategy of the wrapped Analyzers are unknown, PER_FIELD_REUSE_STRATEGY is assumed.
Declaration
[Obsolete("Use AnalyzerWrapper(Analyzer.ReuseStrategy) and specify a valid Analyzer.ReuseStrategy, probably retrieved from the wrapped analyzer using Analyzer.Strategy.")]
protected AnalyzerWrapper()
AnalyzerWrapper(ReuseStrategy)
Creates a new AnalyzerWrapper with the given reuse strategy.
If you want to wrap a single delegate Analyzer you can probably reuse its strategy when instantiating this subclass:base(innerAnalyzer.Strategy)
.
If you choose different analyzers per field, use
PER_FIELD_REUSE_STRATEGY.
Declaration
protected AnalyzerWrapper(ReuseStrategy reuseStrategy)
Parameters
Type | Name | Description |
---|---|---|
ReuseStrategy | reuseStrategy |
See Also
Methods
CreateComponents(string, TextReader)
Creates a new TokenStreamComponents instance for this analyzer.
Declaration
protected override sealed TokenStreamComponents CreateComponents(string fieldName, TextReader aReader)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | the name of the fields content passed to the TokenStreamComponents sink as a reader |
TextReader | aReader |
Returns
Type | Description |
---|---|
TokenStreamComponents | the TokenStreamComponents for this analyzer. |
Overrides
GetOffsetGap(string)
Just like GetPositionIncrementGap(string), except for Token offsets instead. By default this returns 1. this method is only called if the field produced at least one token for indexing.
Declaration
public override int GetOffsetGap(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | the field just indexed |
Returns
Type | Description |
---|---|
int | offset gap, added to the next token emitted from GetTokenStream(string, TextReader).
this value must be |
Overrides
GetPositionIncrementGap(string)
Invoked before indexing a IIndexableField instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between IIndexableField instances using the same field name. The default value position increment gap is 0. With a 0 position increment gap and the typical default token position increment of 1, all terms in a field, including across IIndexableField instances, are in successive positions, allowing exact PhraseQuery matches, for instance, across IIndexableField instance boundaries.
Declaration
public override int GetPositionIncrementGap(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | IIndexableField name being indexed. |
Returns
Type | Description |
---|---|
int | position increment gap, added to the next token emitted from GetTokenStream(string, TextReader).
this value must be |
Overrides
GetWrappedAnalyzer(string)
Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name
Declaration
protected abstract Analyzer GetWrappedAnalyzer(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | Name of the field which is to be analyzed |
Returns
Type | Description |
---|---|
Analyzer | Analyzer for the field with the given name. Assumed to be non-null |
InitReader(string, TextReader)
Override this if you want to add a CharFilter chain.
The default implementation returnsreader
unchanged.
Declaration
protected override TextReader InitReader(string fieldName, TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | IIndexableField name being indexed |
TextReader | reader | original TextReader |
Returns
Type | Description |
---|---|
TextReader | reader, optionally decorated with CharFilter(s) |
Overrides
WrapComponents(string, TokenStreamComponents)
Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components. It is through this method that new TokenFilters can be added by AnalyzerWrappers. By default, the given components are returned.
Declaration
protected virtual TokenStreamComponents WrapComponents(string fieldName, TokenStreamComponents components)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | Name of the field which is to be analyzed |
TokenStreamComponents | components | TokenStreamComponents taken from the wrapped Analyzer |
Returns
Type | Description |
---|---|
TokenStreamComponents | Wrapped / altered TokenStreamComponents. |
WrapReader(string, TextReader)
Wraps / alters the given TextReader. Through this method AnalyzerWrappers can implement InitReader(string, TextReader). By default, the given reader is returned.
Declaration
protected virtual TextReader WrapReader(string fieldName, TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | name of the field which is to be analyzed |
TextReader | reader | the reader to wrap |
Returns
Type | Description |
---|---|
TextReader | the wrapped reader |