Example usage for org.apache.lucene.analysis.payloads DelimitedPayloadTokenFilter incrementToken

List of usage examples for org.apache.lucene.analysis.payloads DelimitedPayloadTokenFilter incrementToken

Introduction

In this page you can find the example usage for org.apache.lucene.analysis.payloads DelimitedPayloadTokenFilter incrementToken.

Prototype

@Override
    public boolean incrementToken() throws IOException 

Source Link

Usage

From source file:org.apache.solr.analysis.TestDelimitedPayloadTokenFilterFactory.java

License:Apache License

public void testEncoder() throws Exception {
    Map<String, String> args = new HashMap<String, String>();
    args.put(DelimitedPayloadTokenFilterFactory.ENCODER_ATTR, "float");
    DelimitedPayloadTokenFilterFactory factory = new DelimitedPayloadTokenFilterFactory();
    factory.init(args);/*from ww  w .  j a  v  a2  s  .  co  m*/
    ResourceLoader loader = new SolrResourceLoader(null, null);
    factory.inform(loader);

    TokenStream input = new WhitespaceTokenizer(DEFAULT_VERSION, new StringReader("the|0.1 quick|0.1 red|0.1"));
    DelimitedPayloadTokenFilter tf = factory.create(input);
    while (tf.incrementToken()) {
        PayloadAttribute payAttr = tf.getAttribute(PayloadAttribute.class);
        assertTrue("payAttr is null and it shouldn't be", payAttr != null);
        byte[] payData = payAttr.getPayload().getData();
        assertTrue("payData is null and it shouldn't be", payData != null);
        assertTrue("payData is null and it shouldn't be", payData != null);
        float payFloat = PayloadHelper.decodeFloat(payData);
        assertTrue(payFloat + " does not equal: " + 0.1f, payFloat == 0.1f);
    }
}

From source file:org.apache.solr.analysis.TestDelimitedPayloadTokenFilterFactory.java

License:Apache License

public void testDelim() throws Exception {
    Map<String, String> args = new HashMap<String, String>();
    args.put(DelimitedPayloadTokenFilterFactory.ENCODER_ATTR, FloatEncoder.class.getName());
    args.put(DelimitedPayloadTokenFilterFactory.DELIMITER_ATTR, "*");
    DelimitedPayloadTokenFilterFactory factory = new DelimitedPayloadTokenFilterFactory();
    factory.init(args);//from w  w w.ja va  2  s  .  co m
    ResourceLoader loader = new SolrResourceLoader(null, null);
    factory.inform(loader);

    TokenStream input = new WhitespaceTokenizer(DEFAULT_VERSION, new StringReader("the*0.1 quick*0.1 red*0.1"));
    DelimitedPayloadTokenFilter tf = factory.create(input);
    while (tf.incrementToken()) {
        PayloadAttribute payAttr = tf.getAttribute(PayloadAttribute.class);
        assertTrue("payAttr is null and it shouldn't be", payAttr != null);
        byte[] payData = payAttr.getPayload().getData();
        assertTrue("payData is null and it shouldn't be", payData != null);
        float payFloat = PayloadHelper.decodeFloat(payData);
        assertTrue(payFloat + " does not equal: " + 0.1f, payFloat == 0.1f);
    }
}