mkhludnev commented on code in PR #12245:
URL: https://github.com/apache/lucene/pull/12245#discussion_r1183824154
##########
lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java:
##########
@@ -391,35 +391,75 @@ private void setScoreAndFreq() throws IOException {
}
this.score = (float) score;
}
-
- public Explanation explain(LeafReaderContext context, Weight childWeight)
throws IOException {
+ /*
+ * This instance of Explanation requires three parameters, context,
childWeight, and scoreMode.
+ * The scoreMode parameter considers Avg, Total, Min, Max, and None.
+ * */
+ public Explanation explain(LeafReaderContext context, Weight childWeight,
ScoreMode scoreMode)
+ throws IOException {
int prevParentDoc = parentBits.prevSetBit(parentApproximation.docID() -
1);
int start =
context.docBase + prevParentDoc + 1; // +1 b/c prevParentDoc is
previous parent doc
int end = context.docBase + parentApproximation.docID() - 1; // -1 b/c
parentDoc is parent doc
Explanation bestChild = null;
+ double childScoreSum = 0;
int matches = 0;
for (int childDoc = start; childDoc <= end; childDoc++) {
Explanation child = childWeight.explain(context, childDoc -
context.docBase);
if (child.isMatch()) {
matches++;
+ childScoreSum += child.getValue().doubleValue();
+
if (bestChild == null
- || child.getValue().floatValue() >
bestChild.getValue().floatValue()) {
+ || child.getValue().doubleValue() >
bestChild.getValue().doubleValue()) {
bestChild = child;
}
}
}
-
- return Explanation.match(
- score(),
- String.format(
- Locale.ROOT,
- "Score based on %d child docs in range from %d to %d, best
match:",
- matches,
- start,
- end),
- bestChild);
+ if (bestChild == null) {
+ if (scoreMode == ScoreMode.None) {
+ return Explanation.noMatch("No children matched");
+
+ } else {
+ return Explanation.match(
+ 0.0f,
+ String.format(
+ Locale.ROOT,
+ "Score based on 0 child docs in range from %d to %d, using
score mode %s",
+ start,
+ end,
+ scoreMode));
+ }
+ }
+ if (scoreMode == ScoreMode.Avg) {
+ double avgScore = matches > 0 ? childScoreSum / (double) matches : 0;
+ return Explanation.match(
+ avgScore,
+ String.format(
+ Locale.ROOT,
+ "Score based on %d child docs in range from %d to %d, using
score mode %s",
+ matches,
+ start,
+ end,
+ scoreMode),
+ bestChild);
+ }
+ if (scoreMode == ScoreMode.Total && matches > 0) {
+ double totalScore = childScoreSum;
+ return Explanation.match(
+ totalScore,
+ String.format(
+ Locale.ROOT,
+ "Score based on %d child docs in range from %d to %d, using
score mode %s",
+ matches,
+ start,
+ end,
+ scoreMode),
+ bestChild);
+ } else {
+ return Explanation.noMatch("Unexpected score mode: " + scoreMode);
Review Comment:
I read it like min/max modes aren't supported. Why?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]