Example usage for org.apache.lucene.analysis.payloads PayloadHelper decodeFloat

List of usage examples for org.apache.lucene.analysis.payloads PayloadHelper decodeFloat

Introduction

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

Prototype

public static float decodeFloat(byte[] bytes) 

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  w ww .  j  av a2s  . c o 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  ww  .  j  a  v a 2  s .c  om
    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);
    }
}