Search in sources :

Example 1 with PayloadScoreQuery

use of org.apache.lucene.queries.payloads.PayloadScoreQuery in project lucene-solr by apache.

the class BoostingTermBuilder method getSpanQuery.

@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    String value = DOMUtils.getNonBlankTextOrFail(e);
    SpanQuery btq = new PayloadScoreQuery(new SpanTermQuery(new Term(fieldName, value)), new AveragePayloadFunction());
    btq = new SpanBoostQuery(btq, DOMUtils.getAttribute(e, "boost", 1.0f));
    return btq;
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) Term(org.apache.lucene.index.Term) AveragePayloadFunction(org.apache.lucene.queries.payloads.AveragePayloadFunction) SpanQuery(org.apache.lucene.search.spans.SpanQuery) PayloadScoreQuery(org.apache.lucene.queries.payloads.PayloadScoreQuery)

Example 2 with PayloadScoreQuery

use of org.apache.lucene.queries.payloads.PayloadScoreQuery in project lucene-solr by apache.

the class PayloadScoreQParserPlugin method createParser.

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

        @Override
        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);
        }
    };
}
Also used : IOException(java.io.IOException) PayloadFunction(org.apache.lucene.queries.payloads.PayloadFunction) Analyzer(org.apache.lucene.analysis.Analyzer) SolrException(org.apache.solr.common.SolrException) FieldType(org.apache.solr.schema.FieldType) SpanQuery(org.apache.lucene.search.spans.SpanQuery) PayloadScoreQuery(org.apache.lucene.queries.payloads.PayloadScoreQuery)

Aggregations

PayloadScoreQuery (org.apache.lucene.queries.payloads.PayloadScoreQuery)2 SpanQuery (org.apache.lucene.search.spans.SpanQuery)2 IOException (java.io.IOException)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 Term (org.apache.lucene.index.Term)1 AveragePayloadFunction (org.apache.lucene.queries.payloads.AveragePayloadFunction)1 PayloadFunction (org.apache.lucene.queries.payloads.PayloadFunction)1 SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1 SolrException (org.apache.solr.common.SolrException)1 FieldType (org.apache.solr.schema.FieldType)1