Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

package org.elasticsearch.search.aggregations.metrics;

import com.carrotsearch.hppc.LongObjectHashMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.FieldDoc;
Expand Down Expand Up @@ -45,6 +42,7 @@
import org.elasticsearch.search.sort.SortAndFormats;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -99,7 +97,7 @@ public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCol
// when post collecting then we have already replaced the leaf readers on the aggregator level have already been
// replaced with the next leaf readers and then post collection pushes docids of the previous segment, which
// then causes assertions to trip or incorrect top docs to be computed.
final LongObjectHashMap<LeafCollector> leafCollectors = new LongObjectHashMap<>(1);
final Map<Long, LeafCollector> leafCollectors = new HashMap<>(1);
return new LeafBucketCollectorBase(sub, null) {

Scorable scorer;
Expand All @@ -108,8 +106,8 @@ public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCol
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
super.setScorer(scorer);
for (ObjectCursor<LeafCollector> cursor : leafCollectors.values()) {
cursor.value.setScorer(scorer);
for (var leaf : leafCollectors.values()) {
leaf.setScorer(scorer);
}
}

Expand Down Expand Up @@ -140,17 +138,18 @@ public void collect(int docId, long bucket) throws IOException {
topDocsCollectors.put(bucket, collectors);
}

final LeafCollector leafCollector;
final int key = leafCollectors.indexOf(bucket);
if (key < 0) {
leafCollector = collectors.collector.getLeafCollector(ctx);
if (scorer != null) {
leafCollector.setScorer(scorer);
final Collector multiCollector = collectors.collector;
final LeafCollector leafCollector = leafCollectors.computeIfAbsent(bucket, k -> {
try {
var leaf = multiCollector.getLeafCollector(ctx);
if (scorer != null) {
leaf.setScorer(scorer);
}
return leaf;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
leafCollectors.indexInsert(key, bucket, leafCollector);
} else {
leafCollector = leafCollectors.indexGet(key);
}
});
leafCollector.collect(docId);
}
};
Expand Down