Class MockAnalyzer
Analyzer for testing.
This analyzer is a replacement for Whitespace/Simple/KeywordAnalyzers for unit tests. If you are testing a custom component such as a queryparser or analyzer-wrapper that consumes analysis streams, its a great idea to test it with this analyzer instead. MockAnalyzer has the following behavior:- By default, the assertions in MockTokenizer are turned on for extra checks that the consumer is consuming properly. These checks can be disabled with EnableChecks.
- Payload data is randomly injected into the stream for more thorough testing of payloads.
Implements
Inherited Members
Namespace: Lucene.Net.Analysis
Assembly: Lucene.Net.TestFramework.dll
Syntax
public sealed class MockAnalyzer : Analyzer, IDisposable
Constructors
MockAnalyzer(Random)
Create a Whitespace-lowercasing analyzer with no stopwords removal.
CallsMockAnalyzer(random, MockTokenizer.WHITESPACE, true, MockTokenFilter.EMPTY_STOPSET, false)
.
Declaration
public MockAnalyzer(Random random)
Parameters
Type | Name | Description |
---|---|---|
Random | random |
See Also
MockAnalyzer(Random, CharacterRunAutomaton, bool)
Calls MockAnalyzer(random, runAutomaton, lowerCase, MockTokenFilter.EMPTY_STOPSET, false)
.
Declaration
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase)
Parameters
Type | Name | Description |
---|---|---|
Random | random | |
CharacterRunAutomaton | runAutomaton | |
bool | lowerCase |
See Also
MockAnalyzer(Random, CharacterRunAutomaton, bool, CharacterRunAutomaton)
Creates a new MockAnalyzer.
Declaration
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase, CharacterRunAutomaton filter)
Parameters
Type | Name | Description |
---|---|---|
Random | random | Random for payloads behavior |
CharacterRunAutomaton | runAutomaton | DFA describing how tokenization should happen (e.g. [a-zA-Z]+) |
bool | lowerCase | true if the tokenizer should lowercase terms |
CharacterRunAutomaton | filter | DFA describing how terms should be filtered (set of stopwords, etc) |
See Also
Properties
EnableChecks
Toggle consumer workflow checking: if your test consumes tokenstreams normally you should leave this enabled.
Declaration
public bool EnableChecks { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
MaxTokenLength
Toggle maxTokenLength for MockTokenizer.
Declaration
public int MaxTokenLength { get; set; }
Property Value
Type | Description |
---|---|
int |
See Also
Methods
CreateComponents(string, TextReader)
Creates a new Lucene.Net.Analysis.TokenStreamComponents instance for this analyzer.
Declaration
protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | the name of the fields content passed to the Lucene.Net.Analysis.TokenStreamComponents sink as a reader |
TextReader | reader | the reader passed to the Lucene.Net.Analysis.Tokenizer constructor |
Returns
Type | Description |
---|---|
TokenStreamComponents | the Lucene.Net.Analysis.TokenStreamComponents for this analyzer. |
Overrides
See Also
GetOffsetGap(string)
Get the offset gap between tokens in fields if several fields with the same name were added.
Declaration
public override int GetOffsetGap(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | Currently not used, the same offset gap is returned for each field. |
Returns
Type | Description |
---|---|
int |
Overrides
See Also
GetPositionIncrementGap(string)
Invoked before indexing a Lucene.Net.Index.IIndexableField instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between Lucene.Net.Index.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 Lucene.Net.Index.IIndexableField instances, are in successive positions, allowing exact Lucene.Net.Search.PhraseQuery matches, for instance, across Lucene.Net.Index.IIndexableField instance boundaries.
Declaration
public override int GetPositionIncrementGap(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
string | fieldName | Lucene.Net.Index.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
See Also
SetOffsetGap(int)
Sets an offset gap which will then be added to the offset when several fields with the same name are indexed
Declaration
public void SetOffsetGap(int offsetGap)
Parameters
Type | Name | Description |
---|---|---|
int | offsetGap |
See Also
SetPositionIncrementGap(int)
Analyzer for testing.
This analyzer is a replacement for Whitespace/Simple/KeywordAnalyzers for unit tests. If you are testing a custom component such as a queryparser or analyzer-wrapper that consumes analysis streams, its a great idea to test it with this analyzer instead. MockAnalyzer has the following behavior:- By default, the assertions in MockTokenizer are turned on for extra checks that the consumer is consuming properly. These checks can be disabled with EnableChecks.
- Payload data is randomly injected into the stream for more thorough testing of payloads.
Declaration
public void SetPositionIncrementGap(int positionIncrementGap)
Parameters
Type | Name | Description |
---|---|---|
int | positionIncrementGap |