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, setPreviousTokenStreampublic 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)
AnalyzertokenStream in class Analyzerpublic TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException
AnalyzerreusableTokenStream in class AnalyzerIOExceptionpublic void setPositionIncrementGap(int positionIncrementGap)
public int getPositionIncrementGap(String fieldName)
AnalyzergetPositionIncrementGap in class AnalyzerfieldName - Fieldable name being indexed.Analyzer.tokenStream(String,Reader)public void setEnableChecks(boolean enableChecks)
public void setMaxTokenLength(int length)