Skip to content

Commit

Permalink
Don't create docCounts equal to maxOrd for the GlobalOrdinalsStringTe…
Browse files Browse the repository at this point in the history
…rmsAggregator.WithHash impl.

Relates #5873
  • Loading branch information
martijnvg committed Apr 25, 2014
1 parent a6a8007 commit 176c039
Showing 1 changed file with 19 additions and 13 deletions.
Expand Up @@ -42,20 +42,16 @@
*/
public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggregator {

private final ValuesSource.Bytes.WithOrdinals.FieldData valuesSource;
private BytesValues.WithOrdinals globalValues;
private Ordinals.Docs globalOrdinals;
protected final ValuesSource.Bytes.WithOrdinals.FieldData valuesSource;
protected BytesValues.WithOrdinals globalValues;
protected Ordinals.Docs globalOrdinals;

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) {
super(name, factories, estimatedBucketCount, aggregationContext, parent, order, requiredSize, shardSize, minDocCount);
this.valuesSource = valuesSource;
}

protected long createBucketOrd(long termOrd) {
return termOrd;
}

protected long getBucketOrd(long termOrd) {
return termOrd;
}
Expand All @@ -77,7 +73,7 @@ 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();
collectExistingBucket(doc, createBucketOrd(globalOrd));
collectExistingBucket(doc, globalOrd);
}
}

Expand Down Expand Up @@ -146,12 +142,22 @@ public WithHash(String name, AggregatorFactories factories, ValuesSource.Bytes.W
}

@Override
protected long createBucketOrd(long termOrd) {
long bucketOrd = bucketOrds.add(termOrd);
if (bucketOrd < 0) {
bucketOrd = -1 - bucketOrd;
public void setNextReader(AtomicReaderContext reader) {
globalValues = valuesSource.globalBytesValues();
globalOrdinals = globalValues.ordinals();
}

@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
Expand Down

0 comments on commit 176c039

Please sign in to comment.