From 58c606d6d988cd14f50ab7390704babfaf905b83 Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 4 Apr 2011 19:53:09 +0300 Subject: [PATCH] break field data value iterator into two callback types, one with support for missing, and one without --- .../elasticsearch/index/field/data/NumericFieldData.java | 6 ++++++ .../index/field/data/bytes/MultiValueByteFieldData.java | 9 +++++++++ .../index/field/data/bytes/SingleValueByteFieldData.java | 8 ++++++++ .../field/data/doubles/MultiValueDoubleFieldData.java | 9 +++++++++ .../field/data/doubles/SingleValueDoubleFieldData.java | 8 ++++++++ .../field/data/floats/MultiValueFloatFieldData.java | 9 +++++++++ .../field/data/floats/SingleValueFloatFieldData.java | 8 ++++++++ .../index/field/data/ints/MultiValueIntFieldData.java | 9 +++++++++ .../index/field/data/ints/SingleValueIntFieldData.java | 8 ++++++++ .../index/field/data/longs/MultiValueLongFieldData.java | 9 +++++++++ .../index/field/data/longs/SingleValueLongFieldData.java | 8 ++++++++ .../field/data/shorts/MultiValueShortFieldData.java | 9 +++++++++ .../field/data/shorts/SingleValueShortFieldData.java | 8 ++++++++ .../histogram/CountAndTotalHistogramFacetCollector.java | 6 ------ .../facet/histogram/CountHistogramFacetCollector.java | 6 ------ .../histogram/KeyValueScriptHistogramFacetCollector.java | 6 ------ .../search/facet/range/KeyValueRangeFacetCollector.java | 6 ------ .../search/facet/range/RangeFacetCollector.java | 6 ------ .../facet/statistical/StatisticalFacetCollector.java | 2 +- .../statistical/StatisticalFieldsFacetCollector.java | 2 +- 20 files changed, 110 insertions(+), 32 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java index b2b2fd30051..64df534d71a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/NumericFieldData.java @@ -94,8 +94,14 @@ public abstract class NumericFieldData extends public abstract void forEachValueInDoc(int docId, DoubleValueInDocProc proc); + public abstract void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc); + public static interface DoubleValueInDocProc { void onValue(int docId, double value); + } + + public static interface MissingDoubleValueInDocProc { + void onValue(int docId, double value); void onMissing(int docId); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java index f55455cbe57..3044d449998 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/MultiValueByteFieldData.java @@ -95,6 +95,15 @@ public class MultiValueByteFieldData extends ByteFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java index 63add03e666..cf4d7c03dae 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/bytes/SingleValueByteFieldData.java @@ -71,6 +71,14 @@ public class SingleValueByteFieldData extends ByteFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java index 54bc9a2dcba..da6d118ad91 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/MultiValueDoubleFieldData.java @@ -84,6 +84,15 @@ public class MultiValueDoubleFieldData extends DoubleFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java index 24251220683..a91ed50310d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/doubles/SingleValueDoubleFieldData.java @@ -64,6 +64,14 @@ public class SingleValueDoubleFieldData extends DoubleFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java index 6fccb26ebc9..1ceb19a9b79 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/MultiValueFloatFieldData.java @@ -95,6 +95,15 @@ public class MultiValueFloatFieldData extends FloatFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java index c0603da7618..3f1070d1dd3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/floats/SingleValueFloatFieldData.java @@ -71,6 +71,14 @@ public class SingleValueFloatFieldData extends FloatFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java index 7ff800fee89..9eade3dd266 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/MultiValueIntFieldData.java @@ -95,6 +95,15 @@ public class MultiValueIntFieldData extends IntFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java index 91980f6963a..0d0a3aa14fd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/ints/SingleValueIntFieldData.java @@ -71,6 +71,14 @@ public class SingleValueIntFieldData extends IntFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java index 778d6888dee..2ada263607f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/MultiValueLongFieldData.java @@ -111,6 +111,15 @@ public class MultiValueLongFieldData extends LongFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java index 187c4824407..05b44b581ea 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/longs/SingleValueLongFieldData.java @@ -81,6 +81,14 @@ public class SingleValueLongFieldData extends LongFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java index d535f4a3472..ba98ffdf151 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/MultiValueShortFieldData.java @@ -95,6 +95,15 @@ public class MultiValueShortFieldData extends ShortFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + for (int[] ordinal : ordinals) { + int loc = ordinal[docId]; + if (loc != 0) { + proc.onValue(docId, values[loc]); + } + } + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { boolean found = false; for (int[] ordinal : ordinals) { int loc = ordinal[docId]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java index 6853fadcf8f..205bb5c18ee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/field/data/shorts/SingleValueShortFieldData.java @@ -71,6 +71,14 @@ public class SingleValueShortFieldData extends ShortFieldData { } @Override public void forEachValueInDoc(int docId, DoubleValueInDocProc proc) { + int loc = ordinals[docId]; + if (loc == 0) { + return; + } + proc.onValue(docId, values[loc]); + } + + @Override public void forEachValueInDoc(int docId, MissingDoubleValueInDocProc proc) { int loc = ordinals[docId]; if (loc == 0) { proc.onMissing(docId); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountAndTotalHistogramFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountAndTotalHistogramFacetCollector.java index 335a9f96cbb..3ae48e31a2e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountAndTotalHistogramFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountAndTotalHistogramFacetCollector.java @@ -101,8 +101,6 @@ public class CountAndTotalHistogramFacetCollector extends AbstractFacetCollector private final TLongDoubleHashMap totals = new TLongDoubleHashMap(); - private int missing; - public HistogramProc(long interval) { this.interval = interval; } @@ -113,10 +111,6 @@ public class CountAndTotalHistogramFacetCollector extends AbstractFacetCollector totals.adjustOrPutValue(bucket, value, value); } - @Override public void onMissing(int docId) { - missing++; - } - public TLongLongHashMap counts() { return counts; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetCollector.java index 37d8411ddf8..bf842fcbca8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetCollector.java @@ -100,8 +100,6 @@ public class CountHistogramFacetCollector extends AbstractFacetCollector { private final TLongLongHashMap counts = CacheRecycler.popLongLongMap(); - private int missing; - public HistogramProc(long interval) { this.interval = interval; } @@ -111,10 +109,6 @@ public class CountHistogramFacetCollector extends AbstractFacetCollector { counts.adjustOrPutValue(bucket, 1, 1); } - @Override public void onMissing(int docId) { - missing++; - } - public TLongLongHashMap counts() { return counts; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/KeyValueScriptHistogramFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/KeyValueScriptHistogramFacetCollector.java index e3c44caac9a..74d69094dc6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/KeyValueScriptHistogramFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/histogram/KeyValueScriptHistogramFacetCollector.java @@ -115,8 +115,6 @@ public class KeyValueScriptHistogramFacetCollector extends AbstractFacetCollecto private final TLongDoubleHashMap totals = new TLongDoubleHashMap(); - private int missing; - public HistogramProc(long interval, SearchScript valueScript) { this.interval = interval; this.valueScript = valueScript; @@ -131,10 +129,6 @@ public class KeyValueScriptHistogramFacetCollector extends AbstractFacetCollecto totals.adjustOrPutValue(bucket, scriptValue, scriptValue); } - @Override public void onMissing(int docId) { - missing++; - } - public TLongLongHashMap counts() { return counts; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/KeyValueRangeFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/KeyValueRangeFacetCollector.java index c0847e6e47f..7ed0f7cb468 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/KeyValueRangeFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/KeyValueRangeFacetCollector.java @@ -101,8 +101,6 @@ public class KeyValueRangeFacetCollector extends AbstractFacetCollector { private final RangeFacet.Entry[] entries; - private int missing; - NumericFieldData valueFieldData; public RangeProc(RangeFacet.Entry[] entries) { @@ -129,9 +127,5 @@ public class KeyValueRangeFacetCollector extends AbstractFacetCollector { } } } - - @Override public void onMissing(int docId) { - missing++; - } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetCollector.java index b447e3e3dc8..989ac5769d3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/range/RangeFacetCollector.java @@ -88,8 +88,6 @@ public class RangeFacetCollector extends AbstractFacetCollector { private final RangeFacet.Entry[] entries; - private int missing; - public RangeProc(RangeFacet.Entry[] entries) { this.entries = entries; } @@ -106,9 +104,5 @@ public class RangeFacetCollector extends AbstractFacetCollector { } } } - - @Override public void onMissing(int docId) { - missing++; - } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetCollector.java index b916b6de39d..fcfd4590c79 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetCollector.java @@ -82,7 +82,7 @@ public class StatisticalFacetCollector extends AbstractFacetCollector { return new InternalStatisticalFacet(facetName, statsProc.min(), statsProc.max(), statsProc.total(), statsProc.sumOfSquares(), statsProc.count()); } - public static class StatsProc implements NumericFieldData.DoubleValueInDocProc { + public static class StatsProc implements NumericFieldData.MissingDoubleValueInDocProc { double min = Double.MAX_VALUE; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFieldsFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFieldsFacetCollector.java index cfe29c80e6a..8c93870f7f5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFieldsFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFieldsFacetCollector.java @@ -87,7 +87,7 @@ public class StatisticalFieldsFacetCollector extends AbstractFacetCollector { return new InternalStatisticalFacet(facetName, statsProc.min(), statsProc.max(), statsProc.total(), statsProc.sumOfSquares(), statsProc.count()); } - public static class StatsProc implements NumericFieldData.DoubleValueInDocProc { + public static class StatsProc implements NumericFieldData.MissingDoubleValueInDocProc { double min = Double.MAX_VALUE;