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 Mock
Tokenizer 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.
Inheritance
Namespace: Lucene.Net.Analysis
Assembly: Lucene.Net.TestFramework.dll
Syntax
public sealed class MockAnalyzer : Analyzer
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 |
---|---|---|
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 |
---|---|---|
Random | random | |
Character |
runAutomaton | |
System. |
lowerCase |
MockAnalyzer(Random, CharacterRunAutomaton, Boolean, CharacterRunAutomaton)
Creates a new Mock
Declaration
public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase, CharacterRunAutomaton filter)
Parameters
Type | Name | Description |
---|---|---|
Random | random | Random for payloads behavior |
Character |
runAutomaton | DFA describing how tokenization should happen (e.g. [a-zA-Z]+) |
System. |
lowerCase | true if the tokenizer should lowercase terms |
Character |
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. |
MaxTokenLength
Toggle maxTokenLength for Mock
Declaration
public int MaxTokenLength { get; set; }
Property Value
Type | Description |
---|---|
System. |
Methods
| Improve this Doc View SourceCreateComponents(String, TextReader)
Declaration
protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
System. |
fieldName | |
Text |
reader |
Returns
Type | Description |
---|---|
Token |
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 |
---|---|---|
System. |
fieldName | Currently not used, the same offset gap is returned for each field. |
Returns
Type | Description |
---|---|
System. |
GetPositionIncrementGap(String)
Declaration
public override int GetPositionIncrementGap(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
System. |
fieldName |
Returns
Type | Description |
---|---|
System. |
SetOffsetGap(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. |
offsetGap |
SetPositionIncrementGap(Int32)
Declaration
public void SetPositionIncrementGap(int positionIncrementGap)
Parameters
Type | Name | Description |
---|---|---|
System. |
positionIncrementGap |