Skip to content

Commit

Permalink
Remove support for min_doc_count=0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Nov 13, 2023
1 parent 0567d9a commit 93a1ad6
Showing 1 changed file with 0 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

package org.elasticsearch.xpack.countedkeyword;

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionContext;
import org.elasticsearch.search.aggregations.Aggregator;
Expand Down Expand Up @@ -90,7 +88,6 @@ public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws I
StringTerms.Bucket[][] topBucketsPerOrd = new StringTerms.Bucket[owningBucketOrds.length][];
long[] otherDocCounts = new long[owningBucketOrds.length];
for (int ordIdx = 0; ordIdx < owningBucketOrds.length; ordIdx++) {
collectZeroDocEntriesIfNeeded(owningBucketOrds[ordIdx]);
int size = (int) Math.min(bucketOrds.size(), bucketCountThresholds.getShardSize());

BucketPriorityQueue<StringTerms.Bucket> ordered = new BucketPriorityQueue<>(size, partiallyBuiltBucketComparator);
Expand Down Expand Up @@ -148,29 +145,6 @@ public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws I
return result;
}

private void collectZeroDocEntriesIfNeeded(long owningBucketOrd) throws IOException {
if (bucketCountThresholds.getMinDocCount() != 0) {
return;
}
if (InternalOrder.isCountDesc(order) && bucketOrds.bucketsInOrd(owningBucketOrd) >= bucketCountThresholds.getRequiredSize()) {
return;
}
// we need to fill-in the blanks
for (LeafReaderContext ctx : searcher().getTopReaderContext().leaves()) {
SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
// brute force
for (int docId = 0; docId < ctx.reader().maxDoc(); ++docId) {
if (values.advanceExact(docId)) {
int valueCount = values.docValueCount();
for (int i = 0; i < valueCount; ++i) {
BytesRef term = values.nextValue();
bucketOrds.add(owningBucketOrd, term);
}
}
}
}
}

@Override
public InternalAggregation buildEmptyAggregation() {
return new StringTerms(
Expand Down

0 comments on commit 93a1ad6

Please sign in to comment.