Search in sources :

Example 1 with BytesTermAttribute

use of org.apache.lucene.analysis.tokenattributes.BytesTermAttribute in project lucene-solr by apache.

the class TestGraphTokenStreamFiniteStrings method assertTokenStream.

private void assertTokenStream(TokenStream ts, String[] terms, int[] increments) throws Exception {
    // verify no nulls and arrays same length
    assertNotNull(ts);
    assertNotNull(terms);
    assertNotNull(increments);
    assertEquals(terms.length, increments.length);
    BytesTermAttribute termAtt = ts.getAttribute(BytesTermAttribute.class);
    PositionIncrementAttribute incrAtt = ts.getAttribute(PositionIncrementAttribute.class);
    int offset = 0;
    while (ts.incrementToken()) {
        // verify term and increment
        assert offset < terms.length;
        assertEquals(terms[offset], termAtt.getBytesRef().utf8ToString());
        assertEquals(increments[offset], incrAtt.getPositionIncrement());
        offset++;
    }
    // make sure we processed all items
    assertEquals(offset, terms.length);
}
Also used : BytesTermAttribute(org.apache.lucene.analysis.tokenattributes.BytesTermAttribute) PositionIncrementAttribute(org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute)

Aggregations

BytesTermAttribute (org.apache.lucene.analysis.tokenattributes.BytesTermAttribute)1 PositionIncrementAttribute (org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute)1