Example usage for org.apache.lucene.analysis.payloads IdentityEncoder IdentityEncoder

List of usage examples for org.apache.lucene.analysis.payloads IdentityEncoder IdentityEncoder

Introduction

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

Prototype

public IdentityEncoder() 

Source Link

Usage

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

License:Apache License

public void inform(ResourceLoader loader) {
    String encoderClass = args.get(ENCODER_ATTR);
    if (encoderClass.equals("float")) {
        encoder = new FloatEncoder();
    } else if (encoderClass.equals("integer")) {
        encoder = new IntegerEncoder();
    } else if (encoderClass.equals("identity")) {
        encoder = new IdentityEncoder();
    } else {//from  w  w  w  .j  a va  2s .com
        encoder = (PayloadEncoder) loader.newInstance(encoderClass);
    }

    String delim = args.get(DELIMITER_ATTR);
    if (delim != null) {
        if (delim.length() == 1) {
            delimiter = delim.charAt(0);
        } else {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                    "Delimiter must be one character only");
        }
    }
}

From source file:org.apache.solr.search.PayloadCheckQParserPlugin.java

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {

    return new QParser(qstr, localParams, params, req) {
        @Override//  ww w  .  j  a v a2s  . co  m
        public Query parse() throws SyntaxError {
            String field = localParams.get(QueryParsing.F);
            String value = localParams.get(QueryParsing.V);
            String p = localParams.get("payloads");

            if (field == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'f' not specified");
            }

            if (value == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "query string missing");
            }

            if (p == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'payloads' not specified");
            }

            FieldType ft = req.getCore().getLatestSchema().getFieldType(field);
            Analyzer analyzer = ft.getQueryAnalyzer();
            SpanQuery query = null;
            try {
                query = PayloadUtils.createSpanQuery(field, value, analyzer);
            } catch (IOException e) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
            }

            if (query == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "SpanQuery is null");
            }

            PayloadEncoder encoder = null;
            String e = PayloadUtils.getPayloadEncoder(ft);
            if ("float".equals(e)) { // TODO: centralize this string->PayloadEncoder logic (see DelimitedPayloadTokenFilterFactory)
                encoder = new FloatEncoder();
            } else if ("integer".equals(e)) {
                encoder = new IntegerEncoder();
            } else if ("identity".equals(e)) {
                encoder = new IdentityEncoder();
            }

            if (encoder == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                        "invalid encoder: " + e + " for field: " + field);
            }

            List<BytesRef> payloads = new ArrayList<>();
            String[] rawPayloads = p.split(" "); // since payloads (most likely) came in whitespace delimited, just split
            for (String rawPayload : rawPayloads) {
                if (rawPayload.length() > 0)
                    payloads.add(encoder.encode(rawPayload.toCharArray()));
            }

            return new SpanPayloadCheckQuery(query, payloads);
        }
    };

}

From source file:org.elasticsearch.analysis.common.DelimitedPayloadTokenFilterFactory.java

License:Apache License

DelimitedPayloadTokenFilterFactory(IndexSettings indexSettings, Environment env, String name,
        Settings settings) {//from   ww  w. j  a  v  a2  s  . c o m
    super(indexSettings, name, settings);
    String delimiterConf = settings.get(DELIMITER);
    if (delimiterConf != null) {
        delimiter = delimiterConf.charAt(0);
    } else {
        delimiter = DEFAULT_DELIMITER;
    }

    if (settings.get(ENCODING) != null) {
        if (settings.get(ENCODING).equals("float")) {
            encoder = new FloatEncoder();
        } else if (settings.get(ENCODING).equals("int")) {
            encoder = new IntegerEncoder();
        } else if (settings.get(ENCODING).equals("identity")) {
            encoder = new IdentityEncoder();
        } else {
            encoder = DEFAULT_ENCODER;
        }
    } else {
        encoder = DEFAULT_ENCODER;
    }
}

From source file:org.elasticsearch.index.analysis.DelimitedPayloadTokenFilterFactory.java

License:Apache License

@Inject
public DelimitedPayloadTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env,
        @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettings, name, settings);
    String delimiterConf = settings.get(DELIMITER);
    if (delimiterConf != null) {
        delimiter = delimiterConf.charAt(0);
    } else {//from   w ww  .j a v a2  s  .c o  m
        delimiter = DEFAULT_DELIMITER;
    }

    if (settings.get(ENCODING) != null) {
        if (settings.get(ENCODING).equals("float")) {
            encoder = new FloatEncoder();
        } else if (settings.get(ENCODING).equals("int")) {
            encoder = new IntegerEncoder();
        } else if (settings.get(ENCODING).equals("identity")) {
            encoder = new IdentityEncoder();
        }
    } else {
        encoder = DEFAULT_ENCODER;
    }
}