mikemccand commented on code in PR #12208:
URL: https://github.com/apache/lucene/pull/12208#discussion_r1157512979
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/TermAutomatonQuery.java:
##########
@@ -442,8 +442,44 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public Explanation explain(LeafReaderContext context, int doc) throws
IOException {
- // TODO
- return null;
+ Scorer scorer = scorer(context);
+ if (scorer == null) {
+ return Explanation.noMatch("No matching terms in the document");
+ }
+
+ int advancedDoc = scorer.iterator().advance(doc);
+ if (advancedDoc != doc) {
+ return Explanation.noMatch("No matching terms in the document");
+ }
+
+ float score = scorer.score();
+ LeafSimScorer leafSimScorer = ((TermAutomatonScorer)
scorer).getLeafSimScorer();
+ EnumAndScorer[] enums = ((TermAutomatonScorer) scorer).getEnums();
+
+ List<Explanation> termExplanations = new ArrayList<>();
+ for (EnumAndScorer enumAndScorer : enums) {
+ if (enumAndScorer != null) {
+ PostingsEnum postingsEnum = enumAndScorer.posEnum;
+ if (postingsEnum.docID() == doc) {
+ float termScore = leafSimScorer.score(doc, postingsEnum.freq());
+ termExplanations.add(
+ Explanation.match(
+ postingsEnum.freq(),
+ "term frequency in the document",
+ Explanation.match(
+ termScore,
+ "score for term: " +
idToTerm.get(enumAndScorer.termID).utf8ToString())));
+ }
+ }
+ }
+
+ if (termExplanations.isEmpty()) {
+ return Explanation.noMatch("No matching terms in the document");
+ }
+
+ Explanation freqExplanation =
+ Explanation.match(score, "TermAutomatonQuery, product of:",
termExplanations);
Review Comment:
Hmm @rmuir noticed that instead of `product of` shouldn't it be `sum of`?
--
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]