mirror of https://github.com/apache/lucene.git
LUCENE-8357: Fix function score explanations
This commit is contained in:
parent
228a84fd6d
commit
6f24be9457
|
@ -291,6 +291,9 @@ Bug Fixes
|
|||
position increment when the preservePositionIncrement setting is false.
|
||||
(David Smiley, Jim Ferenczi)
|
||||
|
||||
* LUCENE-8357: FunctionScoreQuery.boostByQuery() and boostByValue() were
|
||||
producing truncated Explanations (Markus Jelsma, Alan Woodward)
|
||||
|
||||
Other
|
||||
|
||||
* LUCENE-8301: Update randomizedtesting to 2.6.0. (Dawid Weiss)
|
||||
|
|
|
@ -270,6 +270,19 @@ public final class FunctionScoreQuery extends Query {
|
|||
return Objects.equals(boost, that.boost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
if (scoreExplanation.isMatch() == false) {
|
||||
return scoreExplanation;
|
||||
}
|
||||
Explanation boostExpl = boost.explain(ctx, docId, scoreExplanation);
|
||||
if (boostExpl.isMatch() == false) {
|
||||
return scoreExplanation;
|
||||
}
|
||||
return Explanation.match(scoreExplanation.getValue().doubleValue() * boostExpl.getValue().doubleValue(),
|
||||
"product of:", scoreExplanation, boostExpl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(boost);
|
||||
|
@ -345,5 +358,14 @@ public final class FunctionScoreQuery extends Query {
|
|||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return query.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
Explanation inner = query.explain(ctx, docId, scoreExplanation);
|
||||
if (inner.isMatch() == false) {
|
||||
return inner;
|
||||
}
|
||||
return Explanation.match(boost, "Matched boosting query " + query.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,9 +134,12 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
|
|||
assertEquals(plain.totalHits, docs.totalHits);
|
||||
for (int i = 0; i < expectedDocs.length; i++) {
|
||||
assertEquals(expectedDocs[i], docs.scoreDocs[i].doc);
|
||||
|
||||
}
|
||||
|
||||
Explanation expl = searcher.explain(fq, 4);
|
||||
assertTrue(expl.toString().contains("first"));
|
||||
assertTrue(expl.toString().contains("iii"));
|
||||
|
||||
}
|
||||
|
||||
// BoostingQuery equivalent
|
||||
|
@ -155,8 +158,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
|
|||
assertEquals(plain.totalHits, docs.totalHits);
|
||||
for (int i = 0; i < expectedDocs.length; i++) {
|
||||
assertEquals(expectedDocs[i], docs.scoreDocs[i].doc);
|
||||
|
||||
}
|
||||
|
||||
Explanation expl = searcher.explain(fq, 6);
|
||||
assertTrue(expl.toString().contains("rechecking"));
|
||||
assertTrue(expl.toString().contains("text"));
|
||||
}
|
||||
|
||||
// check boosts with non-distributive score source
|
||||
|
|
Loading…
Reference in New Issue