Package org.apache.lucene.analysis.NumericTokenStream

Examples of org.apache.lucene.analysis.NumericTokenStream.NumericTermAttribute


    dir.close();
  }
 
  private void assertNumericContents(int value, TokenStream ts) throws IOException {
    assertTrue(ts instanceof NumericTokenStream);
    NumericTermAttribute numericAtt = ts.getAttribute(NumericTermAttribute.class);
    ts.reset();
    boolean seen = false;
    while (ts.incrementToken()) {
      if (numericAtt.getShift() == 0) {
        assertEquals(value, numericAtt.getRawValue());
        seen = true;
      }
    }
    ts.end();
    ts.close();
View Full Code Here


        NumericDoubleAnalyzer analyzer = new NumericDoubleAnalyzer(precisionStep);

        final TokenStream ts1 = analyzer.tokenStream("dummy", String.valueOf(value));
        final NumericTokenStream ts2 = new NumericTokenStream(precisionStep);
        ts2.setDoubleValue(value);
        final NumericTermAttribute numTerm1 = ts1.addAttribute(NumericTermAttribute.class);
        final NumericTermAttribute numTerm2 = ts1.addAttribute(NumericTermAttribute.class);
        final PositionIncrementAttribute posInc1 = ts1.addAttribute(PositionIncrementAttribute.class);
        final PositionIncrementAttribute posInc2 = ts1.addAttribute(PositionIncrementAttribute.class);
        ts1.reset();
        ts2.reset();
        while (ts1.incrementToken()) {
            assertThat(ts2.incrementToken(), is(true));
            assertThat(posInc1, equalTo(posInc2));
            // can't use equalTo directly on the numeric attribute cause it doesn't implement equals (LUCENE-5070)
            assertThat(numTerm1.getRawValue(), equalTo(numTerm2.getRawValue()));
            assertThat(numTerm2.getShift(), equalTo(numTerm2.getShift()));
        }
        assertThat(ts2.incrementToken(), is(false));
        ts1.end();
        ts2.end();
    }
View Full Code Here

        assertThat(doc.rootDoc().getField(fieldA).tokenStream(defaultMapper.indexAnalyzer(), null), notNullValue());
        assertThat(doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer(), null), notNullValue());
       
        TokenStream tokenStream = doc.rootDoc().getField(fieldA).tokenStream(defaultMapper.indexAnalyzer(), null);
        tokenStream.reset();
        NumericTermAttribute nta = tokenStream.addAttribute(NumericTermAttribute.class);
        List<Long> values = new ArrayList<>();
        while(tokenStream.incrementToken()) {
            values.add(nta.getRawValue());
        }
       
        tokenStream = doc.rootDoc().getField(fieldB).tokenStream(defaultMapper.indexAnalyzer(), null);
        tokenStream.reset();
        nta = tokenStream.addAttribute(NumericTermAttribute.class);
        int pos = 0;
        while(tokenStream.incrementToken()) {
            assertThat(values.get(pos++), equalTo(nta.getRawValue()));
        }
        assertThat(pos, equalTo(values.size()));
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.NumericTokenStream.NumericTermAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.