Apache Lucene open-source search software
LUCENE-6947: Hide SortField.missingValue behind a getter.
Adrien Grand892527c24e36
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 629608a7393..9a2f890b9ac 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -89,6 +89,9 @@ API Changes* LUCENE-6917: Deprecate and rename NumericXXX classes toLegacyNumericXXX in favor of dimensional values (Mike McCandless)+* LUCENE-6947: SortField.missingValue is now protected. You can read its value+ using the new SortField.getMissingValue getter. (Adrien Grand)+Optimizations* LUCENE-6891: Use prefix coding when writing dimensional values indiff --git a/lucene/core/src/java/org/apache/lucene/search/SortField.java b/lucene/core/src/java/org/apache/lucene/search/SortField.javaindex daac17cb4b6..9ff0678dae3 100644--- a/lucene/core/src/java/org/apache/lucene/search/SortField.java+++ b/lucene/core/src/java/org/apache/lucene/search/SortField.java@@ -99,7 +99,7 @@ public class SortField {private FieldComparatorSource comparatorSource;// Used for 'sortMissingFirst/Last'- public Object missingValue = null;+ protected Object missingValue = null;/** Creates a sort by terms in the given field with the type of term* values explicitly given.@@ -141,12 +141,31 @@ public class SortField {}};+ /** Return the value to use for documents that don't have a value.+ * A value of {@code null} indicates that default should be used. */+ public Object getMissingValue() {+ return missingValue;+ }++ /** Set the value to use for documents that don't have a value. */public void setMissingValue(Object missingValue) {if (type == Type.STRING || type == Type.STRING_VAL) {if (missingValue != STRING_FIRST && missingValue != STRING_LAST) {throw new IllegalArgumentException("For STRING type, missing value must be either STRING_FIRST or STRING_LAST");}- } else if (type != Type.INT && type != Type.FLOAT && type != Type.LONG && type != Type.DOUBLE) {+ } else if (type == Type.INT) {+ if (missingValue != null && missingValue.getClass() != Integer.class)+ throw new IllegalArgumentException("Missing values for Type.INT can only be of type java.lang.Integer, but got " + missingValue.getClass());+ } else if (type == Type.LONG) {+ if (missingValue != null && missingValue.getClass() != Long.class)+ throw new IllegalArgumentException("Missing values for Type.LONG can only be of type java.lang.Long, but got " + missingValue.getClass());+ } else if (type == Type.FLOAT) {+ if (missingValue != null && missingValue.getClass() != Float.class)+ throw new IllegalArgumentException("Missing values for Type.FLOAT can only be of type java.lang.Float, but got " + missingValue.getClass());+ } else if (type == Type.DOUBLE) {+ if (missingValue != null && missingValue.getClass() != Double.class)+ throw new IllegalArgumentException("Missing values for Type.DOUBLE can only be of type java.lang.Double, but got " + missingValue.getClass());+ } else {throw new IllegalArgumentException("Missing value only works for numeric or STRING types");}this.missingValue = missingValue;