/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Analyzer for testing
* <p>
* 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:
* <ul>
* <li>By default, the assertions in {@link MockTokenizer} are turned on for extra
* checks that the consumer is consuming properly. These checks can be disabled
* with {@link #setEnableChecks(boolean)}.
* <li>Payload data is randomly injected into the stream for more thorough testing
* of payloads.
* </ul>
* @see MockTokenizer
*/
private final int pattern;
private final boolean lowerCase;
private final boolean enablePositionIncrements;
private int positionIncrementGap;
private boolean enableChecks = true;
/**
* Creates a new MockAnalyzer.
*
* @param random Random for payloads behavior
* @param pattern pattern constant describing how tokenization should happen
* @param lowerCase true if the tokenizer should lowercase terms
* @param filter CharArraySet describing how terms should be filtered (set of stopwords, etc)
* @param enablePositionIncrements true if position increments should reflect filtered terms.
*/
public MockAnalyzer(Random random, int pattern, boolean lowerCase, CharArraySet filter, boolean enablePositionIncrements) {
}
/**
* Calls {@link #MockAnalyzer(Random, int, boolean, CharArraySet, boolean)
* MockAnalyzer(random, pattern, lowerCase, CharArraySet.EMPTY_STOPSET, false}).
*/
}
/**
* Create a Whitespace-lowercasing analyzer with no stopwords removal.
* <p>
* Calls {@link #MockAnalyzer(Random, int, boolean)
* MockAnalyzer(random, MockTokenizer.WHITESPACE, true)}.
*/
}
}
private class SavedStreams {
}
throws IOException {
}
saved = new SavedStreams();
} else {
}
}
break;
break;
break;
}
}
}
if (val == -1)
return stream;
else
}
}
return positionIncrementGap;
}
/**
* Toggle consumer workflow checking: if your test consumes tokenstreams normally you
* should leave this enabled.
*/
this.enableChecks = enableChecks;
}
/**
* Toggle maxTokenLength for MockTokenizer
*/
this.maxTokenLength = length;
}
}