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