Skip to content

Commit

Permalink
Fixed exception for explain in hybrid query when partial match in sub…
Browse files Browse the repository at this point in the history
…queries

Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Jan 18, 2025
1 parent 660f577 commit b28ffea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.lucene.search.Explanation;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
Expand Down Expand Up @@ -99,15 +100,18 @@ public SearchResponse processResponse(
ExplanationDetails normalizationExplanation = combinedExplainDetail.getNormalizationExplanations();
ExplanationDetails combinationExplanation = combinedExplainDetail.getCombinationExplanations();
// Create normalized explanations for each detail
Explanation[] normalizedExplanation = new Explanation[queryLevelExplanation.getDetails().length];
List<Explanation> normalizedExplanation = new ArrayList<>();
for (int i = 0; i < queryLevelExplanation.getDetails().length; i++) {
normalizedExplanation[i] = Explanation.match(
// normalized score
normalizationExplanation.getScoreDetails().get(i).getKey(),
// description of normalized score
normalizationExplanation.getScoreDetails().get(i).getValue(),
// shard level details
queryLevelExplanation.getDetails()[i]
Pair<Float, String> scoreDetail = normalizationExplanation.getScoreDetails().get(0);
normalizedExplanation.add(
Explanation.match(
// normalized score
scoreDetail.getKey(),
// description of normalized score
scoreDetail.getValue(),
// shard level details
queryLevelExplanation.getDetails()[i]
)
);
}
// Create and set final explanation combining all components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio
subsOnMatch.add(e);
max = Math.max(max, score);
} else if (!match) {
subsOnMatch.add(e);
subsOnNoMatch.add(e);
}
}
Expand Down

0 comments on commit b28ffea

Please sign in to comment.