use of org.apache.lucene.analysis.miscellaneous.StemmerOverrideFilter.StemmerOverrideMap in project lucene-solr by apache.
the class TestStemmerOverrideFilter method testRandomRealisticKeyword.
public void testRandomRealisticKeyword() throws IOException {
Map<String, String> map = new HashMap<>();
int numTerms = atLeast(50);
for (int i = 0; i < numTerms; i++) {
String randomRealisticUnicodeString = TestUtil.randomRealisticUnicodeString(random());
if (randomRealisticUnicodeString.length() > 0) {
String value = TestUtil.randomSimpleString(random());
map.put(randomRealisticUnicodeString, value.isEmpty() ? "a" : value);
}
}
if (map.isEmpty()) {
map.put("booked", "books");
}
// This test might fail if ignoreCase is true since the map might have twice the same key, once
// lowercased and once uppercased
StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false);
Set<Entry<String, String>> entrySet = map.entrySet();
for (Entry<String, String> entry : entrySet) {
builder.add(entry.getKey(), entry.getValue());
}
StemmerOverrideMap build = builder.build();
for (Entry<String, String> entry : entrySet) {
if (random().nextBoolean()) {
Tokenizer tokenizer = new KeywordTokenizer();
tokenizer.setReader(new StringReader(entry.getKey()));
TokenStream stream = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, build));
assertTokenStreamContents(stream, new String[] { entry.getValue() });
}
}
}
Aggregations