diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java index e6dc70502709..1040712cad8c 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxBulkScorer.java @@ -54,7 +54,7 @@ private static class BulkScorerAndNext { this.scorers = PriorityQueue.usingComparator(scorers.size(), Comparator.comparingInt(b -> b.next)); for (BulkScorer scorer : scorers) { - this.scorers.add(new BulkScorerAndNext(scorer)); + this.scorers.addNoShift(new BulkScorerAndNext(scorer)); } } @@ -85,7 +85,7 @@ public void setScorer(Scorable scorer) throws IOException { @Override public void collect(int doc) throws IOException { final int delta = doc - windowMin; - windowMatches.set(doc - windowMin); + windowMatches.set(delta); windowScores[delta] = Math.max(windowScores[delta], scorer.score()); } }, diff --git a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java index ec89bb1b2696..43e91457bd96 100644 --- a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java +++ b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java @@ -189,6 +189,18 @@ public final T add(T element) { return heap[1]; } + /** + * Adds an Object to a PriorityQueue without upHeap. Note: only use it when all elements have a + * same value. + */ + public final void addNoShift(T element) { + // TODO: Check element equalsTo lastElement, if we can get the comparator. + + int index = size + 1; + heap[index] = element; + size = index; + } + /** * Adds an Object to a PriorityQueue in log(size) time. It returns the object (if any) that was * dropped off the heap because it was full. This can be the given parameter (in case it is