Skip to content

Apache Lucene open-source search software

Remove deprecated SortField.setMissingValue method (#15486)

Alan Woodwardf4f6d70c0c4c
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 6dda8cfa2e3..4a82ad0c9b9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -46,6 +46,8 @@ API Changes
* GITHUB#15187: Restrict visibility of PerFieldKnnVectorsFormat.FieldsReader (Simon Cooper)
+* GITHUB#15486: Remove deprecated SortField.setMissingValue() method (Alan Woodward)
+
New Features
---------------------
* GITHUB#14097: Binary partitioning merge policy over float-valued vector field. (Mike Sokolov)
diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md
index f70d852199d..8c8466505e7 100644
--- a/lucene/MIGRATE.md
+++ b/lucene/MIGRATE.md
@@ -98,6 +98,10 @@ Any subclass of `DataInput` that have implemented `readGroupVInt()` need to remo
Instead make sure that subclasses of `IndexInput` implement `RandomAccessInput`.
Pure `DataInput` subclasses cannot be optimized anymore as they cannot offer random access and seeking.`
+### SortField.setMissingValue() has been removed
+
+Missing values should be configured in SortField constructor methods, as they are now final.
+
## Migration from Lucene 9.x to Lucene 10.0
### DataInput#readVLong() may now read negative vlongs
diff --git a/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java b/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java
index 09cde894639..4aa0856e77c 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java
@@ -49,11 +49,6 @@ final class FeatureSortField extends SortField {
return new FeatureComparator(numHits, getField(), featureName);
}
- @Override
- public void setMissingValue(Object missingValue) {
- throw new IllegalArgumentException("Missing value not supported for FeatureSortField");
- }
-
@Override
public int hashCode() {
final int prime = 31;
diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java
index e8e0ee36a45..097b6f351ef 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java
@@ -47,16 +47,6 @@ final class LatLonPointSortField extends SortField {
return (Double) super.getMissingValue();
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (Double.valueOf(Double.POSITIVE_INFINITY).equals(missingValue) == false) {
- throw new IllegalArgumentException(
- "Missing value can only be Double.POSITIVE_INFINITY (missing values last), but got "
- + missingValue);
- }
- this.missingValue = missingValue;
- }
-
@Override
public int hashCode() {
final int prime = 31;
diff --git a/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java b/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java
index 2c8c8b4a005..b51287bd5fd 100644
--- a/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java
+++ b/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java
@@ -44,16 +44,6 @@ final class XYPointSortField extends SortField {
return (Double) super.getMissingValue();
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (Double.valueOf(Double.POSITIVE_INFINITY).equals(missingValue) == false) {
- throw new IllegalArgumentException(
- "Missing value can only be Double.POSITIVE_INFINITY (missing values last), but got "
- + missingValue);
- }
- this.missingValue = missingValue;
- }
-
@Override
public int hashCode() {
final int prime = 31;
diff --git a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java
index e6a55316f00..6a3e638539e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java
@@ -529,17 +529,6 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
this.producer = producer;
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (missingValue instanceof Number) {
- this.missingValue = missingValue;
- ((DoubleValuesComparatorSource) getComparatorSource())
- .setMissingValue(((Number) missingValue).doubleValue());
- } else {
- super.setMissingValue(missingValue);
- }
- }
-
@Override
public boolean needsScores() {
return producer.needsScores();
@@ -572,17 +561,13 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
private static class DoubleValuesComparatorSource extends FieldComparatorSource {
private final DoubleValuesSource producer;
- private double missingValue;
+ private final double missingValue;
DoubleValuesComparatorSource(DoubleValuesSource producer, double missingValue) {
this.producer = producer;
this.missingValue = missingValue;
}
- void setMissingValue(double missingValue) {
- this.missingValue = missingValue;
- }
-
@Override
public FieldComparator<Double> newComparator(
String fieldname, int numHits, Pruning pruning, boolean reversed) {
diff --git a/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java
index 86f4f4daff6..f1fee2392cb 100644
--- a/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java
+++ b/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java
@@ -290,17 +290,6 @@ public abstract class LongValuesSource implements SegmentCacheable {
this.producer = producer;
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (missingValue instanceof Number) {
- this.missingValue = missingValue;
- ((LongValuesComparatorSource) getComparatorSource())
- .setMissingValue(((Number) missingValue).longValue());
- } else {
- super.setMissingValue(missingValue);
- }
- }
-
@Override
public boolean needsScores() {
return producer.needsScores();
@@ -333,17 +322,13 @@ public abstract class LongValuesSource implements SegmentCacheable {
private static class LongValuesComparatorSource extends FieldComparatorSource {
private final LongValuesSource producer;
- private long missingValue;
+ private final long missingValue;
public LongValuesComparatorSource(LongValuesSource producer, long missingValue) {
this.producer = producer;
this.missingValue = missingValue;
}
- void setMissingValue(long missingValue) {
- this.missingValue = missingValue;
- }
-
@Override
public FieldComparator<Long> newComparator(
String fieldname, int numHits, Pruning pruning, boolean reversed) {
diff --git a/lucene/core/src/java/org/apache/lucene/search/SortField.java b/lucene/core/src/java/org/apache/lucene/search/SortField.java
index 9cb7f89c155..e97049b4bdc 100644
--- a/lucene/core/src/java/org/apache/lucene/search/SortField.java
+++ b/lucene/core/src/java/org/apache/lucene/search/SortField.java
@@ -133,7 +133,7 @@ public class SortField {
private FieldComparatorSource comparatorSource;
// Used for 'sortMissingFirst/Last'
- protected Object missingValue = null;
+ protected final Object missingValue;
// Indicates if sort should be optimized with indexed data. Set to true by default.
@Deprecated private boolean optimizeSortWithIndexedData = true;
@@ -308,7 +308,7 @@ public class SortField {
}
}
- /** Pass this to {@link #setMissingValue} to have missing string values sort first. */
+ /** Pass this as a missingValue constructor parameter to have missing string values sort first. */
public static final Object STRING_FIRST =
new Object() {
@Override
@@ -317,7 +317,7 @@ public class SortField {
}
};
- /** Pass this to {@link #setMissingValue} to have missing string values sort last. */
+ /** Pass this as a missingValue constructor parameter to have missing string values sort last. */
public static final Object STRING_LAST =
new Object() {
@Override
@@ -334,40 +334,6 @@ public class SortField {
return missingValue;
}
- /** Set the value to use for documents that don't have a value. */
- @Deprecated
- 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) {
- 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;
- }
-
// Sets field & type, and ensures field is not NULL unless
// type is SCORE or DOC
private void validateField(String field, Type type, Object missingValue) {
diff --git a/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java b/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java
index 345a1680510..2ff8fd56ae8 100644
--- a/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java
+++ b/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java
@@ -42,7 +42,7 @@ import org.apache.lucene.util.NumericUtils;
* customized.
*
* <p>Like sorting by string, this also supports sorting missing values as first or last, via {@link
- * #setMissingValue(Object)}.
+ * SortField#STRING_FIRST} or {@link SortField#STRING_LAST}.
*
* @see SortedNumericSelector
*/
@@ -254,11 +254,6 @@ public class SortedNumericSortField extends SortField {
return buffer.toString();
}
- @Override
- public void setMissingValue(Object missingValue) {
- this.missingValue = missingValue;
- }
-
@Override
public FieldComparator<?> getComparator(int numHits, Pruning pruning) {
final FieldComparator<?> fieldComparator;
diff --git a/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java b/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java
index 3a2acbcd571..c94d4f7f5c1 100644
--- a/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java
+++ b/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java
@@ -39,7 +39,7 @@ import org.apache.lucene.store.DataOutput;
* selections happen in constant-time for performance.
*
* <p>Like sorting by string, this also supports sorting missing values as first or last, via {@link
- * #setMissingValue(Object)}.
+ * SortField#STRING_FIRST} or {@link SortField#STRING_LAST}.
*
* @see SortedSetSelector
*/
@@ -169,20 +169,6 @@ public class SortedSetSortField extends SortField {
return buffer.toString();
}
- /**
- * Set how missing values (the empty set) are sorted.
- *
- * <p>Note that this must be {@link #STRING_FIRST} or {@link #STRING_LAST}.
- */
- @Override
- public void setMissingValue(Object missingValue) {
- if (missingValue != STRING_FIRST && missingValue != STRING_LAST) {
- throw new IllegalArgumentException(
- "For SORTED_SET type, missing value must be either STRING_FIRST or STRING_LAST");
- }
- this.missingValue = missingValue;
- }
-
@Override
public FieldComparator<?> getComparator(int numHits, Pruning pruning) {
Pruning finalPruning = getOptimizeSortWithIndexedData() ? pruning : Pruning.NONE;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java
index d45dd5a681c..f268dbf1c96 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java
@@ -50,16 +50,6 @@ final class Geo3DPointOutsideSortField extends SortField {
return (Double) super.getMissingValue();
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (Double.valueOf(Double.POSITIVE_INFINITY).equals(missingValue) == false) {
- throw new IllegalArgumentException(
- "Missing value can only be Double.POSITIVE_INFINITY (missing values last), but got "
- + missingValue);
- }
- this.missingValue = missingValue;
- }
-
@Override
public int hashCode() {
final int prime = 31;
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java
index 1873cc94e5a..b902c0386c6 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java
@@ -50,16 +50,6 @@ final class Geo3DPointSortField extends SortField {
return (Double) super.getMissingValue();
}
- @Override
- public void setMissingValue(Object missingValue) {
- if (Double.valueOf(Double.POSITIVE_INFINITY).equals(missingValue) == false) {
- throw new IllegalArgumentException(
- "Missing value can only be Double.POSITIVE_INFINITY (missing values last), but got "
- + missingValue);
- }
- this.missingValue = missingValue;
- }
-
@Override
public int hashCode() {
final int prime = 31;