use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestSuggestSpellingConverter method assertConvertsTo.
public void assertConvertsTo(String text, String[] expected) throws IOException {
Collection<Token> tokens = converter.convert(text);
TokenStream ts = new CannedTokenStream(tokens.toArray(new Token[0]));
assertTokenStreamContents(ts, expected);
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class ShingleFilterTest method shingleFilterTest.
protected void shingleFilterTest(int minSize, int maxSize, Token[] tokensToShingle, Token[] tokensToCompare, int[] positionIncrements, String[] types, boolean outputUnigrams, boolean outputUnigramsIfNoShingles) throws IOException {
ShingleFilter filter = new ShingleFilter(new CannedTokenStream(tokensToShingle), minSize, maxSize);
filter.setOutputUnigrams(outputUnigrams);
filter.setOutputUnigramsIfNoShingles(outputUnigramsIfNoShingles);
shingleFilterTestCommon(filter, tokensToCompare, positionIncrements, types);
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestLegacyFieldReuse method testNumericReuse.
public void testNumericReuse() throws IOException {
LegacyIntField legacyIntField = new LegacyIntField("foo", 5, Field.Store.NO);
// passing null
TokenStream ts = legacyIntField.tokenStream(null, null);
assertTrue(ts instanceof LegacyNumericTokenStream);
assertEquals(LegacyNumericUtils.PRECISION_STEP_DEFAULT_32, ((LegacyNumericTokenStream) ts).getPrecisionStep());
assertNumericContents(5, ts);
// now reuse previous stream
legacyIntField = new LegacyIntField("foo", 20, Field.Store.NO);
TokenStream ts2 = legacyIntField.tokenStream(null, ts);
assertSame(ts, ts2);
assertNumericContents(20, ts);
// pass a bogus stream and ensure it's still ok
legacyIntField = new LegacyIntField("foo", 2343, Field.Store.NO);
TokenStream bogus = new CannedTokenStream(new Token("bogus", 0, 5));
ts = legacyIntField.tokenStream(null, bogus);
assertNotSame(bogus, ts);
assertNumericContents(2343, ts);
// pass another bogus stream (numeric, but different precision step!)
legacyIntField = new LegacyIntField("foo", 42, Field.Store.NO);
assert 3 != LegacyNumericUtils.PRECISION_STEP_DEFAULT;
bogus = new LegacyNumericTokenStream(3);
ts = legacyIntField.tokenStream(null, bogus);
assertNotSame(bogus, ts);
assertNumericContents(42, ts);
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestFlattenGraphFilter method testWTF1.
public void testWTF1() throws Exception {
// "wow that's funny" and "what the fudge" are separate side paths, in parallel with "wtf", on input:
TokenStream in = new CannedTokenStream(0, 12, new Token[] { token("wtf", 1, 5, 0, 3), token("what", 0, 1, 0, 3), token("wow", 0, 3, 0, 3), token("the", 1, 1, 0, 3), token("fudge", 1, 3, 0, 3), token("that's", 1, 1, 0, 3), token("funny", 1, 1, 0, 3), token("happened", 1, 1, 4, 12) });
TokenStream out = new FlattenGraphFilter(in);
// ... but on output, it's flattened to wtf/what/wow that's/the fudge/funny happened:
assertTokenStreamContents(out, new String[] { "wtf", "what", "wow", "the", "that's", "fudge", "funny", "happened" }, new int[] { 0, 0, 0, 0, 0, 0, 0, 4 }, new int[] { 3, 3, 3, 3, 3, 3, 3, 12 }, new int[] { 1, 0, 0, 1, 0, 1, 0, 1 }, new int[] { 3, 1, 1, 1, 1, 1, 1, 1 }, 12);
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestFlattenGraphFilter method testSimpleHole.
public void testSimpleHole() throws Exception {
TokenStream in = new CannedTokenStream(0, 13, new Token[] { token("hello", 1, 1, 0, 5), token("hole", 2, 1, 6, 10), token("fun", 1, 1, 11, 13) });
TokenStream out = new FlattenGraphFilter(in);
// ... but on output, it's flattened to wtf/what/wow that's/the fudge/funny happened:
assertTokenStreamContents(out, new String[] { "hello", "hole", "fun" }, new int[] { 0, 6, 11 }, new int[] { 5, 10, 13 }, new int[] { 1, 2, 1 }, new int[] { 1, 1, 1 }, 13);
}
Aggregations