Example usage for org.apache.lucene.analysis.payloads DelimitedPayloadTokenFilterFactory inform

List of usage examples for org.apache.lucene.analysis.payloads DelimitedPayloadTokenFilterFactory inform

Introduction

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

Prototype

@Override
    public void inform(ResourceLoader loader) 

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);/*w  w  w.  ja  v  a 2 s .  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 va 2s. 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);
        float payFloat = PayloadHelper.decodeFloat(payData);
        assertTrue(payFloat + " does not equal: " + 0.1f, payFloat == 0.1f);
    }
}