use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestStopFilter method testExactCase.
// other StopFilter functionality is already tested by TestStopAnalyzer
public void testExactCase() throws IOException {
StringReader reader = new StringReader("Now is The Time");
CharArraySet stopWords = new CharArraySet(asSet("is", "the", "Time"), false);
final MockTokenizer in = new MockTokenizer(MockTokenizer.WHITESPACE, false);
in.setReader(reader);
TokenStream stream = new StopFilter(in, stopWords);
assertTokenStreamContents(stream, new String[] { "Now", "The" });
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testNonZeroOffset.
public void testNonZeroOffset() {
String[] words = { "Hello", "World", "this", "is", "a", "test" };
char[] findme = "xthisy".toCharArray();
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(words));
assertTrue(set.contains(findme, 1, 4));
assertTrue(set.contains(new String(findme, 1, 4)));
// test unmodifiable
set = CharArraySet.unmodifiableSet(set);
assertTrue(set.contains(findme, 1, 4));
assertTrue(set.contains(new String(findme, 1, 4)));
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testClear.
public void testClear() {
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(TEST_STOP_WORDS));
assertEquals("Not all words added", TEST_STOP_WORDS.length, set.size());
set.clear();
assertEquals("not empty", 0, set.size());
for (int i = 0; i < TEST_STOP_WORDS.length; i++) assertFalse(set.contains(TEST_STOP_WORDS[i]));
set.addAll(Arrays.asList(TEST_STOP_WORDS));
assertEquals("Not all words added", TEST_STOP_WORDS.length, set.size());
for (int i = 0; i < TEST_STOP_WORDS.length; i++) assertTrue(set.contains(TEST_STOP_WORDS[i]));
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testUnmodifiableSet.
public void testUnmodifiableSet() {
CharArraySet set = new CharArraySet(10, true);
set.addAll(Arrays.asList(TEST_STOP_WORDS));
set.add(Integer.valueOf(1));
final int size = set.size();
set = CharArraySet.unmodifiableSet(set);
assertEquals("Set size changed due to unmodifiableSet call", size, set.size());
for (String stopword : TEST_STOP_WORDS) {
assertTrue(set.contains(stopword));
}
assertTrue(set.contains(Integer.valueOf(1)));
assertTrue(set.contains("1"));
assertTrue(set.contains(new char[] { '1' }));
expectThrows(NullPointerException.class, () -> {
CharArraySet.unmodifiableSet(null);
});
}
use of org.apache.lucene.analysis.CharArraySet in project lucene-solr by apache.
the class TestCharArraySet method testToString.
public void testToString() {
CharArraySet set = CharArraySet.copy(Collections.singleton("test"));
assertEquals("[test]", set.toString());
set.add("test2");
assertTrue(set.toString().contains(", "));
}
Aggregations