Slight improvement/optimization to duplicate facet value checking (ref: LUCENE-9964) (#234)

This commit is contained in:
Greg Miller 2021-08-06 12:57:09 -07:00 committed by GitHub
parent 645b64ef4e
commit 3037e33025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -162,14 +162,14 @@ public class LongValueFacetCounts extends Facets {
if (limit > 0) {
totCount++;
}
long previousValue = 0;
long previousValue = -1;
for (int i = 0; i < limit; i++) {
long value = multiValues.nextValue();
// do not increment the count for duplicate values
if (i == 0 || value != previousValue) {
if (value != previousValue) {
increment(value);
previousValue = value;
}
previousValue = value;
}
}
}
@ -214,14 +214,14 @@ public class LongValueFacetCounts extends Facets {
if (limit > 0) {
totCount++;
}
long previousValue = 0;
long previousValue = -1;
for (int i = 0; i < limit; i++) {
long value = multiValues.nextValue();
// do not increment the count for duplicate values
if (i == 0 || value != previousValue) {
if (value != previousValue) {
increment(value);
previousValue = value;
}
previousValue = value;
}
}
}

View File

@ -193,8 +193,13 @@ abstract class RangeFacetCounts extends Facets {
totCount++;
} else {
counter.startMultiValuedDoc();
long previous = -1;
for (int j = 0; j < limit; j++) {
counter.addMultiValued(mapDocValue(multiValues.nextValue()));
long val = mapDocValue(multiValues.nextValue());
if (val != previous) {
counter.addMultiValued(val);
previous = val;
}
}
if (counter.endMultiValuedDoc()) {
totCount++;