Don't create docCounts equal to maxOrd for the GlobalOrdinalsStringTermsAggregator.WithHash impl.

Relates #5873
This commit is contained in:
Martijn van Groningen 2014-04-26 00:01:52 +07:00
parent eb9805389a
commit a2aa167e6e
1 changed files with 19 additions and 13 deletions

View File

@ -42,9 +42,9 @@ import java.util.Arrays;
*/ */
public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggregator { public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggregator {
private final ValuesSource.Bytes.WithOrdinals.FieldData valuesSource; protected final ValuesSource.Bytes.WithOrdinals.FieldData valuesSource;
private BytesValues.WithOrdinals globalValues; protected BytesValues.WithOrdinals globalValues;
private Ordinals.Docs globalOrdinals; protected Ordinals.Docs globalOrdinals;
public GlobalOrdinalsStringTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals.FieldData valuesSource, long estimatedBucketCount, public GlobalOrdinalsStringTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals.FieldData valuesSource, long estimatedBucketCount,
InternalOrder order, int requiredSize, int shardSize, long minDocCount, AggregationContext aggregationContext, Aggregator parent) { InternalOrder order, int requiredSize, int shardSize, long minDocCount, AggregationContext aggregationContext, Aggregator parent) {
@ -52,10 +52,6 @@ public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggr
this.valuesSource = valuesSource; this.valuesSource = valuesSource;
} }
protected long createBucketOrd(long termOrd) {
return termOrd;
}
protected long getBucketOrd(long termOrd) { protected long getBucketOrd(long termOrd) {
return termOrd; return termOrd;
} }
@ -77,7 +73,7 @@ public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggr
final int numOrds = globalOrdinals.setDocument(doc); final int numOrds = globalOrdinals.setDocument(doc);
for (int i = 0; i < numOrds; i++) { for (int i = 0; i < numOrds; i++) {
final long globalOrd = globalOrdinals.nextOrd(); final long globalOrd = globalOrdinals.nextOrd();
collectExistingBucket(doc, createBucketOrd(globalOrd)); collectExistingBucket(doc, globalOrd);
} }
} }
@ -146,12 +142,22 @@ public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggr
} }
@Override @Override
protected long createBucketOrd(long termOrd) { public void setNextReader(AtomicReaderContext reader) {
long bucketOrd = bucketOrds.add(termOrd); globalValues = valuesSource.globalBytesValues();
if (bucketOrd < 0) { globalOrdinals = globalValues.ordinals();
bucketOrd = -1 - bucketOrd; }
@Override
public void collect(int doc, long owningBucketOrdinal) throws IOException {
final int numOrds = globalOrdinals.setDocument(doc);
for (int i = 0; i < numOrds; i++) {
final long globalOrd = globalOrdinals.nextOrd();
long bucketOrd = bucketOrds.add(globalOrd);
if (bucketOrd < 0) {
bucketOrd = -1 - bucketOrd;
}
collectBucket(doc, bucketOrd);
} }
return bucketOrd;
} }
@Override @Override