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
| Improve this Doc View SourceMockAnalyzer(Random)
Create a Whitespace-lowercasing analyzer with no stopwords removal.
Calls MockAnalyzer(random, MockTokenizer.WHITESPACE, true, MockTokenFilter.EMPTY_STOPSET, false).
Declaration
public MockAnalyzer(Random random)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Random | random |
MockAnalyzer(Random, CharacterRunAutomaton, Boolean)
Calls MockAnalyzer(random, runAutomaton, lowerCase, MockTokenFilter.EMPTY_STOPSET, false).
Declaration
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Random | random | |
| CharacterRunAutomaton | runAutomaton | |
| System.Boolean | lowerCase |
MockAnalyzer(Random, CharacterRunAutomaton, Boolean, CharacterRunAutomaton)
Creates a new MockAnalyzer.
Declaration
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase, CharacterRunAutomaton filter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Random | random | Random for payloads behavior |
| CharacterRunAutomaton | runAutomaton | DFA describing how tokenization should happen (e.g. [a-zA-Z]+) |
| System.Boolean | lowerCase | true if the tokenizer should lowercase terms |
| CharacterRunAutomaton | filter | DFA describing how terms should be filtered (set of stopwords, etc) |
Properties
| Improve this Doc View SourceEnableChecks
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 |
|---|---|
| System.Boolean |
MaxTokenLength
Toggle maxTokenLength for MockTokenizer.
Declaration
public int MaxTokenLength { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
| Improve this Doc View SourceCreateComponents(String, TextReader)
Declaration
protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fieldName | |
| System.IO.TextReader | reader |
Returns
| Type | Description |
|---|---|
| TokenStreamComponents |
Overrides
| Improve this Doc View SourceGetOffsetGap(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 |
|---|---|---|
| System.String | fieldName | Currently not used, the same offset gap is returned for each field. |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
| Improve this Doc View SourceGetPositionIncrementGap(String)
Declaration
public override int GetPositionIncrementGap(string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fieldName |
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
| Improve this Doc View SourceSetOffsetGap(Int32)
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 |
|---|---|---|
| System.Int32 | offsetGap |
SetPositionIncrementGap(Int32)
Declaration
public void SetPositionIncrementGap(int positionIncrementGap)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | positionIncrementGap |