LUCENE-7996: PayloadScoreQuery must produce positive scores.

This commit is contained in:
Adrien Grand 2017-12-06 19:15:13 +01:00
parent 63b63c5734
commit 187849f9b6
1 changed files with 13 additions and 2 deletions

View File

@ -233,11 +233,22 @@ public class PayloadScoreQuery extends SpanQuery {
}
protected float getPayloadScore() {
return function.docScore(docID(), getField(), spans.payloadsSeen, spans.payloadScore);
float score = function.docScore(docID(), getField(), spans.payloadsSeen, spans.payloadScore);
if (score >= 0 == false) {
return 0;
} else {
return score;
}
}
protected Explanation getPayloadExplanation() {
return function.explain(docID(), getField(), spans.payloadsSeen, spans.payloadScore);
Explanation expl = function.explain(docID(), getField(), spans.payloadsSeen, spans.payloadScore);
if (expl.getValue() < 0) {
expl = Explanation.match(0, "truncated score, max of:", Explanation.match(0f, "minimum score"), expl);
} else if (Float.isNaN(expl.getValue())) {
expl = Explanation.match(0, "payload score, computed as (score == NaN ? 0 : score) since NaN is an illegal score from:", expl);
}
return expl;
}
protected float getSpanScore() throws IOException {