Mikep86 commented on code in PR #13697:
URL: https://github.com/apache/lucene/pull/13697#discussion_r1736812026


##########
lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java:
##########
@@ -440,6 +500,83 @@ private String formatScoreExplanation(int matches, int 
start, int end, ScoreMode
     }
   }
 
+  private abstract static class BatchAwareLeafCollector extends 
FilterLeafCollector {
+    public BatchAwareLeafCollector(LeafCollector in) {
+      super(in);
+    }
+
+    public void endBatch(int doc) throws IOException {}
+  }
+
+  private static class BlockJoinBulkScorer extends BulkScorer {
+    private final BulkScorer childBulkScorer;
+    private final ScoreMode scoreMode;
+    private final BitSet parents;
+    private final Score currentParentScore;
+    private Integer currentParent;
+
+    public BlockJoinBulkScorer(BulkScorer childBulkScorer, ScoreMode 
scoreMode, BitSet parents) {
+      this.childBulkScorer = childBulkScorer;
+      this.scoreMode = scoreMode;
+      this.parents = parents;
+      this.currentParentScore = new Score(scoreMode);
+      this.currentParent = null;
+    }
+
+    @Override
+    public int score(LeafCollector collector, Bits acceptDocs, int min, int 
max)
+        throws IOException {
+      BatchAwareLeafCollector wrappedCollector = wrapCollector(collector);
+      childBulkScorer.score(wrappedCollector, acceptDocs, min, max);
+      wrappedCollector.endBatch(max);
+      return max;
+    }
+
+    @Override
+    public long cost() {
+      return childBulkScorer.cost();
+    }
+
+    // TODO: Need to resolve parent doc IDs in multi-reader space?
+    private BatchAwareLeafCollector wrapCollector(LeafCollector collector) {
+      return new BatchAwareLeafCollector(collector) {
+        private Scorable scorer = null;
+
+        @Override
+        public void setScorer(Scorable scorer) throws IOException {
+          this.scorer = scorer;
+          super.setScorer(scorer != null ? currentParentScore : null);
+        }
+
+        @Override
+        public void collect(int doc) throws IOException {
+          if (currentParent == null) {
+            currentParent = parents.nextSetBit(doc);
+          } else if (doc > currentParent) {
+            in.collect(currentParent); // Emit the current parent
+
+            // Get the next parent and reset the score
+            currentParent = parents.nextSetBit(doc);
+            currentParentScore.reset();
+          }
+
+          if (scorer != null && scoreMode != ScoreMode.None) {
+            currentParentScore.addChildScore(scorer.score());
+          }
+        }
+
+        @Override
+        public void endBatch(int doc) throws IOException {
+          if (currentParent != null && doc > currentParent) {

Review Comment:
   I think we can do this once we update `score` to according to your earlier 
comment. As currently implemented, if `doc == currentParent`, we cannot emit 
the parent because it equals `max`, causing assertions to fail.



-- 
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