Example usage for org.apache.lucene.queries.payloads PayloadScoreQuery PayloadScoreQuery

List of usage examples for org.apache.lucene.queries.payloads PayloadScoreQuery PayloadScoreQuery

Introduction

In this page you can find the example usage for org.apache.lucene.queries.payloads PayloadScoreQuery PayloadScoreQuery.

Prototype

public PayloadScoreQuery(SpanQuery wrappedQuery, PayloadFunction function, PayloadDecoder decoder) 

Source Link

Document

Creates a new PayloadScoreQuery that includes the underlying span scores

Usage

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

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {
        @Override/*from   w  ww .j av  a  2s.  c om*/
        public Query parse() throws SyntaxError {
            String field = localParams.get(QueryParsing.F);
            String value = localParams.get(QueryParsing.V);
            String func = localParams.get("func");
            boolean includeSpanScore = localParams.getBool("includeSpanScore", false);

            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");
            }

            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");
            }

            // note: this query(/parser) does not support func=first; 'first' is a payload() value source feature only
            PayloadFunction payloadFunction = PayloadUtils.getPayloadFunction(func);
            if (payloadFunction == null)
                throw new SyntaxError("Unknown payload function: " + func);

            return new PayloadScoreQuery(query, payloadFunction, includeSpanScore);
        }
    };
}