From a9239f81473bdc1b1fb1c28bdf8d6207b75ce0bb Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 31 Oct 2013 14:18:16 +0100 Subject: [PATCH] Guarantee sorted order for [Double|Long|Bytes]Values Values returned by [Double|Long|Bytes]Values are sorted today which is guaranteed by the underlying Lucene index. Several implementations can make use of this property but the interfaces don't guarantee this behavior. This commit adds the guarantees and makes use of them in several places. Note: This change might require sorting for 3rd party implemenations of these interaces. --- .../AbstractAtomicNumericFieldData.java | 11 ++ .../index/fielddata/AtomicFieldData.java | 32 +++++ .../index/fielddata/BytesValues.java | 16 ++- .../index/fielddata/DoubleValues.java | 14 ++ .../index/fielddata/FilterBytesValues.java | 5 + .../index/fielddata/FilterDoubleValues.java | 7 + .../index/fielddata/FilterLongValues.java | 5 + .../index/fielddata/GeoPointValues.java | 14 ++ .../index/fielddata/LongValues.java | 14 ++ .../BytesRefValComparator.java | 63 +-------- .../fielddata/fieldcomparator/SortMode.java | 128 +++++++++++++++++- .../SortedSetDVNumericAtomicFieldData.java | 5 + .../index/fielddata/DuelFieldDataTests.java | 56 +++++++- .../index/fielddata/LongFieldDataTests.java | 12 +- 14 files changed, 313 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/fielddata/AbstractAtomicNumericFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AbstractAtomicNumericFieldData.java index 0c569bfbfa0..9de15a08eab 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/AbstractAtomicNumericFieldData.java +++ b/src/main/java/org/elasticsearch/index/fielddata/AbstractAtomicNumericFieldData.java @@ -58,6 +58,12 @@ public abstract class AbstractAtomicNumericFieldData implements AtomicNumericFie scratch.copyChars(Double.toString(values.nextValue())); return scratch; } + + @Override + public Order getOrder() { + return values.getOrder(); + } + }; } else { final LongValues values = getLongValues(); @@ -74,6 +80,11 @@ public abstract class AbstractAtomicNumericFieldData implements AtomicNumericFie scratch.copyChars(Long.toString(values.nextValue())); return scratch; } + + @Override + public Order getOrder() { + return values.getOrder(); + } }; } } diff --git a/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java index 07df8caef0d..06af537f0b0 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java +++ b/src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java @@ -79,4 +79,36 @@ public interface AtomicFieldData