public final class MockAnalyzer extends Analyzer
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:
MockTokenizer
are turned on for extra
checks that the consumer is consuming properly. These checks can be disabled
with setEnableChecks(boolean)
.
MockTokenizer
Constructor and Description |
---|
MockAnalyzer(Random random)
Create a Whitespace-lowercasing analyzer with no stopwords removal.
|
MockAnalyzer(Random random,
int pattern,
boolean lowerCase)
|
MockAnalyzer(Random random,
int pattern,
boolean lowerCase,
CharArraySet filter,
boolean enablePositionIncrements)
Creates a new MockAnalyzer.
|
Modifier and Type | Method and Description |
---|---|
int |
getPositionIncrementGap(String fieldName)
Invoked before indexing a Fieldable instance if
terms have already been added to that field.
|
TokenStream |
reusableTokenStream(String fieldName,
Reader reader)
Creates a TokenStream that is allowed to be re-used
from the previous time that the same thread called
this method.
|
void |
setEnableChecks(boolean enableChecks)
Toggle consumer workflow checking: if your test consumes tokenstreams normally you
should leave this enabled.
|
void |
setMaxTokenLength(int length)
Toggle maxTokenLength for MockTokenizer
|
void |
setPositionIncrementGap(int positionIncrementGap) |
TokenStream |
tokenStream(String fieldName,
Reader reader)
Creates a TokenStream which tokenizes all the text in the provided
Reader.
|
close, getOffsetGap, getPreviousTokenStream, setPreviousTokenStream
public MockAnalyzer(Random random, int pattern, boolean lowerCase, CharArraySet filter, boolean enablePositionIncrements)
random
- Random for payloads behaviorpattern
- pattern constant describing how tokenization should happenlowerCase
- true if the tokenizer should lowercase termsfilter
- CharArraySet describing how terms should be filtered (set of stopwords, etc)enablePositionIncrements
- true if position increments should reflect filtered terms.public MockAnalyzer(Random random, int pattern, boolean lowerCase)
public MockAnalyzer(Random random)
public TokenStream tokenStream(String fieldName, Reader reader)
Analyzer
tokenStream
in class Analyzer
public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException
Analyzer
reusableTokenStream
in class Analyzer
IOException
public void setPositionIncrementGap(int positionIncrementGap)
public int getPositionIncrementGap(String fieldName)
Analyzer
getPositionIncrementGap
in class Analyzer
fieldName
- Fieldable name being indexed.Analyzer.tokenStream(String,Reader)
public void setEnableChecks(boolean enableChecks)
public void setMaxTokenLength(int length)