|
@@ -438,6 +438,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return HalfFloatPoint.halfFloatToSortableShort(value.floatValue());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IndexFieldData.Builder getFieldDataBuilder(MappedFieldType ft, ValuesSourceType valuesSourceType) {
|
|
|
return new SortedDoublesIndexFieldData.Builder(
|
|
@@ -622,6 +627,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return NumericUtils.floatToSortableInt(value.floatValue());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IndexFieldData.Builder getFieldDataBuilder(MappedFieldType ft, ValuesSourceType valuesSourceType) {
|
|
|
return new SortedDoublesIndexFieldData.Builder(
|
|
@@ -772,6 +782,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return NumericUtils.doubleToSortableLong(value.doubleValue());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IndexFieldData.Builder getFieldDataBuilder(MappedFieldType ft, ValuesSourceType valuesSourceType) {
|
|
|
return new SortedDoublesIndexFieldData.Builder(
|
|
@@ -891,6 +906,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
INTEGER.addFields(document, name, value, indexed, docValued, stored);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return INTEGER.toSortableLong(value);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
Number valueForSearch(Number value) {
|
|
|
return value.byteValue();
|
|
@@ -1009,6 +1029,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
INTEGER.addFields(document, name, value, indexed, docValued, stored);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return INTEGER.toSortableLong(value);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
Number valueForSearch(Number value) {
|
|
|
return value.shortValue();
|
|
@@ -1206,6 +1231,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return value.intValue();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IndexFieldData.Builder getFieldDataBuilder(MappedFieldType ft, ValuesSourceType valuesSourceType) {
|
|
|
return new SortedNumericIndexFieldData.Builder(
|
|
@@ -1358,6 +1388,11 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public long toSortableLong(Number value) {
|
|
|
+ return value.longValue();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IndexFieldData.Builder getFieldDataBuilder(MappedFieldType ft, ValuesSourceType valuesSourceType) {
|
|
|
return new SortedNumericIndexFieldData.Builder(
|
|
@@ -1506,6 +1541,13 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
boolean stored
|
|
|
);
|
|
|
|
|
|
+ /**
|
|
|
+ * For a given {@code Number}, returns the sortable long representation that will be stored in the doc values.
|
|
|
+ * @param value number to convert
|
|
|
+ * @return sortable long representation
|
|
|
+ */
|
|
|
+ public abstract long toSortableLong(Number value);
|
|
|
+
|
|
|
public FieldValues<Number> compile(String fieldName, Script script, ScriptCompiler compiler) {
|
|
|
// only implemented for long and double fields
|
|
|
throw new IllegalArgumentException("Unknown parameter [script] for mapper [" + fieldName + "]");
|
|
@@ -2140,7 +2182,10 @@ public class NumberFieldMapper extends FieldMapper {
|
|
|
}
|
|
|
if (offsetsFieldName != null && context.isImmediateParentAnArray() && context.canAddIgnoredField()) {
|
|
|
if (value != null) {
|
|
|
- context.getOffSetContext().recordOffset(offsetsFieldName, (Comparable<?>) value);
|
|
|
+ // We cannot simply cast value to Comparable<> because we need to also capture the potential loss of precision that occurs
|
|
|
+ // when the value is stored into the doc values.
|
|
|
+ long sortableLongValue = type.toSortableLong(value);
|
|
|
+ context.getOffSetContext().recordOffset(offsetsFieldName, sortableLongValue);
|
|
|
} else {
|
|
|
context.getOffSetContext().recordNull(offsetsFieldName);
|
|
|
}
|