MarcusSorealheis commented on code in PR #12208:
URL: https://github.com/apache/lucene/pull/12208#discussion_r1157688385


##########
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:
   fixed in 
[1a0c77a](https://github.com/apache/lucene/pull/12208/commits/1a0c77a44995ef74025c82f6d84d87cc94b4988c)



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to