faster handling of a case where each doc has multi valued values fields in histogram facet

This commit is contained in:
kimchy 2011-04-07 14:52:25 +03:00
parent 7fcf82af80
commit b479bc58f9
2 changed files with 48 additions and 44 deletions

View File

@ -121,6 +121,8 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
NumericFieldData valueFieldData; NumericFieldData valueFieldData;
final ValueAggregator valueAggregator = new ValueAggregator();
public HistogramProc(long from, long to, long interval, long offset, int size) { public HistogramProc(long from, long to, long interval, long offset, int size) {
this.from = from; this.from = from;
this.to = to; this.to = to;
@ -138,18 +140,11 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
InternalBoundedFullHistogramFacet.FullEntry entry = (InternalBoundedFullHistogramFacet.FullEntry) entries[index]; InternalBoundedFullHistogramFacet.FullEntry entry = (InternalBoundedFullHistogramFacet.FullEntry) entries[index];
if (entry == null) { if (entry == null) {
if (valueFieldData.multiValued()) { if (valueFieldData.multiValued()) {
double[] valuesValues = valueFieldData.doubleValues(docId); entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 1, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 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[index] = entry; entries[index] = entry;
valueAggregator.entry = entry;
valueFieldData.forEachValueInDoc(docId, valueAggregator);
} else { } else {
double valueValue = valueFieldData.doubleValue(docId); double valueValue = valueFieldData.doubleValue(docId);
entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 1, valueValue, valueValue, 1, valueValue); entry = new InternalBoundedFullHistogramFacet.FullEntry(index, 1, valueValue, valueValue, 1, valueValue);
@ -158,17 +153,8 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
} else { } else {
entry.count++; entry.count++;
if (valueFieldData.multiValued()) { if (valueFieldData.multiValued()) {
double[] valuesValues = valueFieldData.doubleValues(docId); valueAggregator.entry = entry;
entry.totalCount += valuesValues.length; valueFieldData.forEachValueInDoc(docId, valueAggregator);
for (double valueValue : valuesValues) {
entry.total += valueValue;
if (valueValue < entry.min) {
entry.min = valueValue;
}
if (valueValue > entry.max) {
entry.max = valueValue;
}
}
} else { } else {
entry.totalCount++; entry.totalCount++;
double valueValue = valueFieldData.doubleValue(docId); double valueValue = valueFieldData.doubleValue(docId);
@ -182,5 +168,22 @@ public class BoundedValueHistogramFacetCollector extends AbstractFacetCollector
} }
} }
} }
public static class ValueAggregator implements NumericFieldData.DoubleValueInDocProc {
InternalBoundedFullHistogramFacet.FullEntry 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;
}
}
}
} }
} }

View File

@ -109,6 +109,8 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
NumericFieldData valueFieldData; NumericFieldData valueFieldData;
final ValueAggregator valueAggregator = new ValueAggregator();
public HistogramProc(long interval) { public HistogramProc(long interval) {
this.interval = interval; this.interval = interval;
} }
@ -118,18 +120,10 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
InternalFullHistogramFacet.FullEntry entry = entries.get(bucket); InternalFullHistogramFacet.FullEntry entry = entries.get(bucket);
if (entry == null) { if (entry == null) {
if (valueFieldData.multiValued()) { if (valueFieldData.multiValued()) {
double[] valuesValues = valueFieldData.doubleValues(docId); entry = new InternalFullHistogramFacet.FullEntry(bucket, 1, Double.MAX_VALUE, Double.MIN_VALUE, 0, 0);
entry = new InternalFullHistogramFacet.FullEntry(bucket, 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(bucket, entry); entries.put(bucket, entry);
valueAggregator.entry = entry;
valueFieldData.forEachValueInDoc(docId, valueAggregator);
} else { } else {
double valueValue = valueFieldData.doubleValue(docId); double valueValue = valueFieldData.doubleValue(docId);
entry = new InternalFullHistogramFacet.FullEntry(bucket, 1, valueValue, valueValue, 1, valueValue); entry = new InternalFullHistogramFacet.FullEntry(bucket, 1, valueValue, valueValue, 1, valueValue);
@ -138,17 +132,8 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
} else { } else {
entry.count++; entry.count++;
if (valueFieldData.multiValued()) { if (valueFieldData.multiValued()) {
double[] valuesValues = valueFieldData.doubleValues(docId); valueAggregator.entry = entry;
entry.totalCount += valuesValues.length; valueFieldData.forEachValueInDoc(docId, valueAggregator);
for (double valueValue : valuesValues) {
entry.total += valueValue;
if (valueValue < entry.min) {
entry.min = valueValue;
}
if (valueValue > entry.max) {
entry.max = valueValue;
}
}
} else { } else {
entry.totalCount++; entry.totalCount++;
double valueValue = valueFieldData.doubleValue(docId); double valueValue = valueFieldData.doubleValue(docId);
@ -162,5 +147,21 @@ public class ValueHistogramFacetCollector extends AbstractFacetCollector {
} }
} }
} }
public static class ValueAggregator implements NumericFieldData.DoubleValueInDocProc {
InternalFullHistogramFacet.FullEntry 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;
}
}
}
} }
} }