Search in sources :

Example 1 with NumericPayloadTokenFilterFactory

use of org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory in project lucene-solr by apache.

the class PayloadUtils method getPayloadEncoder.

public static String getPayloadEncoder(FieldType fieldType) {
    // TODO: support custom payload encoding fields too somehow - maybe someone has a custom component that encodes payloads as floats
    String encoder = null;
    Analyzer a = fieldType.getIndexAnalyzer();
    if (a instanceof TokenizerChain) {
        // examine the indexing analysis chain for DelimitedPayloadTokenFilterFactory or NumericPayloadTokenFilterFactory
        TokenizerChain tc = (TokenizerChain) a;
        TokenFilterFactory[] factories = tc.getTokenFilterFactories();
        for (TokenFilterFactory factory : factories) {
            if (factory instanceof DelimitedPayloadTokenFilterFactory) {
                encoder = factory.getOriginalArgs().get(DelimitedPayloadTokenFilterFactory.ENCODER_ATTR);
                break;
            }
            if (factory instanceof NumericPayloadTokenFilterFactory) {
                // encodes using `PayloadHelper.encodeFloat(payload)`
                encoder = "float";
                break;
            }
        }
    }
    return encoder;
}
Also used : TokenizerChain(org.apache.solr.analysis.TokenizerChain) DelimitedPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory) Analyzer(org.apache.lucene.analysis.Analyzer) NumericPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory) DelimitedPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory) NumericPayloadTokenFilterFactory(org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory)

Aggregations

Analyzer (org.apache.lucene.analysis.Analyzer)1 DelimitedPayloadTokenFilterFactory (org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory)1 NumericPayloadTokenFilterFactory (org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory)1 TokenFilterFactory (org.apache.lucene.analysis.util.TokenFilterFactory)1 TokenizerChain (org.apache.solr.analysis.TokenizerChain)1