faster handling of a case where each doc has multi valued values for different facets, also, don't take into account missing value values (and in the future, we can also count those per bucket if needed)
This commit is contained in:
parent
b479bc58f9
commit
4603d10501
|
@ -111,6 +111,8 @@ public class ValueDateHistogramFacetCollector extends AbstractFacetCollector {
|
|||
|
||||
NumericFieldData valueFieldData;
|
||||
|
||||
final ValueAggregator valueAggregator = new ValueAggregator();
|
||||
|
||||
public DateHistogramProc(long interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
@ -123,48 +125,26 @@ public class ValueDateHistogramFacetCollector extends AbstractFacetCollector {
|
|||
|
||||
InternalFullDateHistogramFacet.FullEntry entry = entries.get(time);
|
||||
if (entry == null) {
|
||||
if (valueFieldData.multiValued()) {
|
||||
double[] valuesValues = valueFieldData.doubleValues(docId);
|
||||
entry = new InternalFullDateHistogramFacet.FullEntry(time, 1, Double.MAX_VALUE, Double.MIN_VALUE, valuesValues.length, 0);
|
||||
for (double valueValue : valuesValues) {
|
||||
entry.total += valueValue;
|
||||
if (valueValue < entry.min) {
|
||||
entry.min = valueValue;
|
||||
}
|
||||
if (valueValue > entry.max) {
|
||||
entry.max = valueValue;
|
||||
}
|
||||
}
|
||||
entries.put(time, entry);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry = new InternalFullDateHistogramFacet.FullEntry(time, 1, valueValue, valueValue, 1, valueValue);
|
||||
entries.put(time, entry);
|
||||
entry = new InternalFullDateHistogramFacet.FullEntry(time, 0, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
|
||||
entries.put(time, entry);
|
||||
}
|
||||
entry.count++;
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
public static class ValueAggregator implements NumericFieldData.DoubleValueInDocProc {
|
||||
|
||||
InternalFullDateHistogramFacet.FullEntry entry;
|
||||
|
||||
@Override public void onValue(int docId, double value) {
|
||||
entry.totalCount++;
|
||||
entry.total += value;
|
||||
if (value < entry.min) {
|
||||
entry.min = value;
|
||||
}
|
||||
} else {
|
||||
entry.count++;
|
||||
if (valueFieldData.multiValued()) {
|
||||
double[] valuesValues = valueFieldData.doubleValues(docId);
|
||||
entry.totalCount += valuesValues.length;
|
||||
for (double valueValue : valuesValues) {
|
||||
entry.total += valueValue;
|
||||
if (valueValue < entry.min) {
|
||||
entry.min = valueValue;
|
||||
}
|
||||
if (valueValue > entry.max) {
|
||||
entry.max = valueValue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
entry.totalCount++;
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry.total += valueValue;
|
||||
if (valueValue < entry.min) {
|
||||
entry.min = valueValue;
|
||||
}
|
||||
if (valueValue > entry.max) {
|
||||
entry.max = valueValue;
|
||||
}
|
||||
if (value > entry.max) {
|
||||
entry.max = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ public class ValueGeoDistanceFacetCollector extends GeoDistanceFacetCollector {
|
|||
|
||||
NumericFieldData valueFieldData;
|
||||
|
||||
final ValueAggregator valueAggregator = new ValueAggregator();
|
||||
|
||||
public Aggregator(double lat, double lon, GeoDistance geoDistance, DistanceUnit unit, GeoDistanceFacet.Entry[] entries) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
|
@ -89,31 +91,26 @@ public class ValueGeoDistanceFacetCollector extends GeoDistanceFacetCollector {
|
|||
if (distance >= entry.getFrom() && distance < entry.getTo()) {
|
||||
entry.foundInDoc = true;
|
||||
entry.count++;
|
||||
if (valueFieldData.multiValued()) {
|
||||
double[] values = valueFieldData.doubleValues(docId);
|
||||
entry.totalCount += values.length;
|
||||
for (double value : values) {
|
||||
entry.total += value;
|
||||
if (value < entry.min) {
|
||||
entry.min = value;
|
||||
}
|
||||
if (value > entry.max) {
|
||||
entry.max = value;
|
||||
}
|
||||
}
|
||||
} else if (valueFieldData.hasValue(docId)) {
|
||||
entry.totalCount++;
|
||||
double value = valueFieldData.doubleValue(docId);
|
||||
entry.total += value;
|
||||
if (value < entry.min) {
|
||||
entry.min = value;
|
||||
}
|
||||
if (value > entry.max) {
|
||||
entry.max = value;
|
||||
}
|
||||
}
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ValueAggregator implements NumericFieldData.DoubleValueInDocProc {
|
||||
|
||||
GeoDistanceFacet.Entry entry;
|
||||
|
||||
@Override public void onValue(int docId, double value) {
|
||||
entry.totalCount++;
|
||||
entry.total += value;
|
||||
if (value < entry.min) {
|
||||
entry.min = value;
|
||||
}
|
||||
if (value > entry.max) {
|
||||
entry.max = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,34 +139,12 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
|
|||
int index = ((int) ((value + offset) / interval));
|
||||
InternalBoundedFullHistogramFacet.FullEntry entry = (InternalBoundedFullHistogramFacet.FullEntry) entries[index];
|
||||
if (entry == null) {
|
||||
if (valueFieldData.multiValued()) {
|
||||
entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 1, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
|
||||
entries[index] = entry;
|
||||
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 1, valueValue, valueValue, 1, valueValue);
|
||||
entries[index] = entry;
|
||||
}
|
||||
} else {
|
||||
entry.count++;
|
||||
if (valueFieldData.multiValued()) {
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
entry.totalCount++;
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry.total += valueValue;
|
||||
if (valueValue < entry.min) {
|
||||
entry.min = valueValue;
|
||||
}
|
||||
if (valueValue > entry.max) {
|
||||
entry.max = valueValue;
|
||||
}
|
||||
}
|
||||
entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 0, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
|
||||
entries[index] = entry;
|
||||
}
|
||||
entry.count++;
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,33 +119,12 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
|
|||
long bucket = FullHistogramFacetCollector.bucket(value, interval);
|
||||
InternalFullHistogramFacet.FullEntry entry = entries.get(bucket);
|
||||
if (entry == null) {
|
||||
if (valueFieldData.multiValued()) {
|
||||
entry = new InternalFullHistogramFacet.FullEntry(bucket, 1, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
|
||||
entries.put(bucket, entry);
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry = new InternalFullHistogramFacet.FullEntry(bucket, 1, valueValue, valueValue, 1, valueValue);
|
||||
entries.put(bucket, entry);
|
||||
}
|
||||
} else {
|
||||
entry.count++;
|
||||
if (valueFieldData.multiValued()) {
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
entry.totalCount++;
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
entry.total += valueValue;
|
||||
if (valueValue < entry.min) {
|
||||
entry.min = valueValue;
|
||||
}
|
||||
if (valueValue > entry.max) {
|
||||
entry.max = valueValue;
|
||||
}
|
||||
}
|
||||
entry = new InternalFullHistogramFacet.FullEntry(bucket, 0, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
|
||||
entries.put(bucket, entry);
|
||||
}
|
||||
entry.count++;
|
||||
valueAggregator.entry = entry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
public static class ValueAggregator implements NumericFieldData.DoubleValueInDocProc {
|
||||
|
|
|
@ -162,26 +162,12 @@ public class TermsStatsDoubleFacetCollector extends AbstractFacetCollector {
|
|||
@Override public void onValue(int docId, double value) {
|
||||
InternalTermsStatsDoubleFacet.DoubleEntry doubleEntry = entries.get(value);
|
||||
if (doubleEntry == null) {
|
||||
doubleEntry = new InternalTermsStatsDoubleFacet.DoubleEntry(value, 1, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
doubleEntry = new InternalTermsStatsDoubleFacet.DoubleEntry(value, 0, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
entries.put(value, doubleEntry);
|
||||
} else {
|
||||
doubleEntry.count++;
|
||||
}
|
||||
|
||||
if (valueFieldData.multiValued()) {
|
||||
valueAggregator.doubleEntry = doubleEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
if (valueValue < doubleEntry.min) {
|
||||
doubleEntry.min = valueValue;
|
||||
}
|
||||
if (valueValue > doubleEntry.max) {
|
||||
doubleEntry.max = valueValue;
|
||||
}
|
||||
doubleEntry.totalCount++;
|
||||
doubleEntry.total += valueValue;
|
||||
}
|
||||
doubleEntry.count++;
|
||||
valueAggregator.doubleEntry = doubleEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
|
|
|
@ -165,25 +165,12 @@ public class TermsStatsLongFacetCollector extends AbstractFacetCollector {
|
|||
@Override public void onValue(int docId, long value) {
|
||||
InternalTermsStatsLongFacet.LongEntry longEntry = entries.get(value);
|
||||
if (longEntry == null) {
|
||||
longEntry = new InternalTermsStatsLongFacet.LongEntry(value, 1, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
longEntry = new InternalTermsStatsLongFacet.LongEntry(value, 0, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
entries.put(value, longEntry);
|
||||
} else {
|
||||
longEntry.count++;
|
||||
}
|
||||
if (valueFieldData.multiValued()) {
|
||||
valueAggregator.longEntry = longEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
if (valueValue < longEntry.min) {
|
||||
longEntry.min = valueValue;
|
||||
}
|
||||
if (valueValue > longEntry.max) {
|
||||
longEntry.max = valueValue;
|
||||
}
|
||||
longEntry.totalCount++;
|
||||
longEntry.total += valueValue;
|
||||
}
|
||||
longEntry.count++;
|
||||
valueAggregator.longEntry = longEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
|
|
|
@ -164,26 +164,12 @@ public class TermsStatsStringFacetCollector extends AbstractFacetCollector {
|
|||
@Override public void onValue(int docId, String value) {
|
||||
InternalTermsStatsStringFacet.StringEntry stringEntry = entries.get(value);
|
||||
if (stringEntry == null) {
|
||||
stringEntry = new InternalTermsStatsStringFacet.StringEntry(value, 1, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
stringEntry = new InternalTermsStatsStringFacet.StringEntry(value, 0, 0, 0, Double.MAX_VALUE, Double.MIN_VALUE);
|
||||
entries.put(value, stringEntry);
|
||||
} else {
|
||||
stringEntry.count++;
|
||||
}
|
||||
if (valueFieldData.multiValued()) {
|
||||
valueAggregator.stringEntry = stringEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
} else {
|
||||
double valueValue = valueFieldData.doubleValue(docId);
|
||||
if (valueValue < stringEntry.min) {
|
||||
stringEntry.min = valueValue;
|
||||
}
|
||||
if (valueValue > stringEntry.max) {
|
||||
stringEntry.max = valueValue;
|
||||
}
|
||||
stringEntry.total += valueValue;
|
||||
stringEntry.totalCount++;
|
||||
|
||||
}
|
||||
stringEntry.count++;
|
||||
valueAggregator.stringEntry = stringEntry;
|
||||
valueFieldData.forEachValueInDoc(docId, valueAggregator);
|
||||
}
|
||||
|
||||
@Override public void onMissing(int docId) {
|
||||
|
|
Loading…
Reference in New Issue