Skip to content

Commit 17ced9b

Browse files
Remove overdue deprecated SortField optimization toggle methods
Remove setOptimizeSortWithIndexedData, getOptimizeSortWithIndexedData, setOptimizeSortWithPoints, and getOptimizeSortWithPoints from SortField. These methods were marked '@deprecated // Remove in Lucene 10' for compatibility with 8.x indices. Since we are now on Lucene 11, sort optimization is unconditionally enabled. Also cleaned up the corresponding disableSkipping() calls in SortedNumericSortField and SortedSetSortField, and removed test paths in TestSortOptimization that exercised the disabled-optimization mode.
1 parent 610484e commit 17ced9b

5 files changed

Lines changed: 11 additions & 160 deletions

File tree

lucene/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ Build
235235
Other
236236
---------------------
237237

238+
* GITHUB#XXXXX: Removed overdue deprecated methods setOptimizeSortWithIndexedData and
239+
setOptimizeSortWithPoints (along with their getters) from SortField. Sort optimization
240+
is now unconditionally enabled when possible. (Bharathi Kanna)
238241
* GITHUB#16074: Ban presized collection#toArray. (Zhou Hui)
239242

240243
* GITHUB#16063: Remove redundant final modifiers. (Zhou Hui)

lucene/core/src/java/org/apache/lucene/search/SortField.java

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ public enum Type {
133133
// Used for 'sortMissingFirst/Last'
134134
protected final Object missingValue;
135135

136-
// Indicates if sort should be optimized with indexed data. Set to true by default.
137-
@Deprecated private boolean optimizeSortWithIndexedData = true;
138-
139136
/**
140137
* Creates a sort by terms in the given field with the type of term values explicitly given.
141138
*
@@ -530,9 +527,7 @@ public FieldComparator<?> getComparator(final int numHits, Pruning pruning) {
530527
default:
531528
throw new IllegalStateException("Illegal sort type: " + type);
532529
}
533-
if (getOptimizeSortWithIndexedData() == false) {
534-
fieldComparator.disableSkipping();
535-
}
530+
536531
return fieldComparator;
537532
}
538533

@@ -604,68 +599,4 @@ public IndexSorter getIndexSorter() {
604599
return null;
605600
}
606601
}
607-
608-
/**
609-
* Enables/disables numeric sort optimization to use the indexed data.
610-
*
611-
* <p>Enabled by default. By default, sorting on a numeric field activates point sort optimization
612-
* that can efficiently skip over non-competitive hits. Sort optimization has a number of
613-
* requirements, one of which is that SortField.Type matches the Point type with which the field
614-
* was indexed (e.g. sort on IntPoint field should use SortField.Type.INT). Another requirement is
615-
* that the same data is indexed with points and doc values for the field.
616-
*
617-
* <p>By default, sorting on a SORTED(_SET) field activates sort optimization that can efficiently
618-
* skip over non-competitive hits. Sort optimization requires that the same data is indexed with
619-
* term index and doc values for the field.
620-
*
621-
* @param optimizeSortWithIndexedData providing {@code false} disables the optimization, in cases
622-
* where these requirements can't be met.
623-
* @deprecated should only be used for compatibility with 8.x indices that got created with
624-
* inconsistent data across fields, or the wrong sort configuration in the index sort
625-
*/
626-
@Deprecated // Remove in Lucene 10
627-
public void setOptimizeSortWithIndexedData(boolean optimizeSortWithIndexedData) {
628-
this.optimizeSortWithIndexedData = optimizeSortWithIndexedData;
629-
}
630-
631-
/**
632-
* Returns whether sort optimization should be optimized with indexed data
633-
*
634-
* @return whether sort optimization should be optimized with indexed data
635-
*/
636-
@Deprecated // Remove in Lucene 10
637-
public boolean getOptimizeSortWithIndexedData() {
638-
return optimizeSortWithIndexedData;
639-
}
640-
641-
/**
642-
* Enables/disables numeric sort optimization to use the Points index.
643-
*
644-
* <p>Enabled by default. By default, sorting on a numeric field activates point sort optimization
645-
* that can efficiently skip over non-competitive hits. Sort optimization has a number of
646-
* requirements, one of which is that SortField.Type matches the Point type with which the field
647-
* was indexed (e.g. sort on IntPoint field should use SortField.Type.INT). Another requirement is
648-
* that the same data is indexed with points and doc values for the field.
649-
*
650-
* @param optimizeSortWithPoints providing {@code false} disables the optimization, in cases where
651-
* these requirements can't be met.
652-
* @deprecated should only be used for compatibility with 8.x indices that got created with
653-
* inconsistent data across fields, or the wrong sort configuration in the index sort. This is
654-
* a duplicate method for {@code SortField#setOptimizeSortWithIndexedData}.
655-
*/
656-
@Deprecated // Remove in Lucene 10
657-
public void setOptimizeSortWithPoints(boolean optimizeSortWithPoints) {
658-
setOptimizeSortWithIndexedData(optimizeSortWithPoints);
659-
}
660-
661-
/**
662-
* Returns whether sort optimization should be optimized with points index
663-
*
664-
* @return whether sort optimization should be optimized with points index
665-
* @deprecated This is a duplicate method for {@code SortField#getOptimizeSortWithIndexedData}.
666-
*/
667-
@Deprecated // Remove in Lucene 10
668-
public boolean getOptimizeSortWithPoints() {
669-
return getOptimizeSortWithIndexedData();
670-
}
671602
}

lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,7 @@ protected NumericDocValues getNumericDocValues(
359359
default:
360360
throw new AssertionError();
361361
}
362-
if (getOptimizeSortWithIndexedData() == false) {
363-
fieldComparator.disableSkipping();
364-
}
362+
365363
return fieldComparator;
366364
}
367365

lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ public String toString() {
171171

172172
@Override
173173
public FieldComparator<?> getComparator(int numHits, Pruning pruning) {
174-
Pruning finalPruning = getOptimizeSortWithIndexedData() ? pruning : Pruning.NONE;
175174
return new TermOrdValComparator(
176-
numHits, getField(), missingValue == STRING_LAST, reverse, finalPruning) {
175+
numHits, getField(), missingValue == STRING_LAST, reverse, pruning) {
177176
@Override
178177
protected SortedDocValues getSortedDocValues(LeafReaderContext context, String field)
179178
throws IOException {

lucene/core/src/test/org/apache/lucene/search/TestSortOptimization.java

Lines changed: 5 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -331,33 +331,11 @@ private void testNumericDocValuesOptimizationWithMissingValues(
331331
final DirectoryReader reader = DirectoryReader.open(writer);
332332
writer.close();
333333
final int numHits = 3;
334-
TopDocs topDocs1;
335-
TopDocs topDocs2;
336-
337334
{ // Test that optimization is run with NumericDocValues when missing value is NOT competitive
338335
final SortField sortField = new SortField("my_field", SortField.Type.LONG, true, 0L);
339336
final Sort sort = new Sort(sortField);
340-
topDocs1 = assertSearchHits(reader, sort, numHits, null);
341-
assertNonCompetitiveHitsAreSkipped(topDocs1.totalHits.value(), numDocs);
342-
}
343-
{ // Test that sort on sorted numeric field without sort optimization and with sort optimization
344-
// produce the same results
345-
final SortField sortField = new SortField("my_field", SortField.Type.LONG, true, 0L);
346-
final Sort sort = new Sort(sortField);
347-
sortField.setOptimizeSortWithPoints(false);
348-
topDocs2 = assertSearchHits(reader, sort, numHits, null);
349-
// assert that the resulting hits are the same
350-
assertEquals(topDocs1.scoreDocs.length, topDocs2.scoreDocs.length);
351-
assertEquals(topDocs1.scoreDocs.length, numHits);
352-
ScoreDoc[] scoreDocs1 = topDocs1.scoreDocs;
353-
ScoreDoc[] scoreDocs2 = topDocs2.scoreDocs;
354-
for (int i = 0; i < numHits; i++) {
355-
FieldDoc fieldDoc = (FieldDoc) scoreDocs1[i];
356-
FieldDoc fieldDoc2 = (FieldDoc) scoreDocs2[i];
357-
assertEquals(fieldDoc.fields[0], fieldDoc2.fields[0]);
358-
assertEquals(fieldDoc.doc, fieldDoc2.doc);
359-
}
360-
assertTrue(topDocs1.totalHits.value() < topDocs2.totalHits.value());
337+
TopDocs topDocs = assertSearchHits(reader, sort, numHits, null);
338+
assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value(), numDocs);
361339
}
362340

363341
{ // Test that we can't do optimization via NumericDocValues when there are multiple comparators
@@ -795,25 +773,15 @@ public void testPointValidation() throws IOException {
795773
assertThrows(
796774
IllegalArgumentException.class,
797775
() -> searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(longSortOnIntField)));
798-
// assert that when sort optimization is disabled we can use LONG sort on int field
799-
longSortOnIntField.setOptimizeSortWithIndexedData(false);
800-
searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(longSortOnIntField));
801-
802776
SortField intSortOnLongField = new SortField("longField", SortField.Type.INT);
803777
assertThrows(
804778
IllegalArgumentException.class,
805779
() -> searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(intSortOnLongField)));
806-
// assert that when sort optimization is disabled we can use INT sort on long field
807-
intSortOnLongField.setOptimizeSortWithIndexedData(false);
808-
searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(intSortOnLongField));
809780

810781
SortField intSortOnIntRangeField = new SortField("intRange", SortField.Type.INT);
811782
assertThrows(
812783
IllegalArgumentException.class,
813784
() -> searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(intSortOnIntRangeField)));
814-
// assert that when sort optimization is disabled we can use INT sort on intRange field
815-
intSortOnIntRangeField.setOptimizeSortWithIndexedData(false);
816-
searcher.search(MatchAllDocsQuery.INSTANCE, 1, new Sort(intSortOnIntRangeField));
817785

818786
reader.close();
819787
dir.close();
@@ -948,14 +916,8 @@ public void testSortOptimizationOnSortedNumericField() throws IOException {
948916
RandomPicks.randomFrom(random(), SortedNumericSelector.Type.values());
949917
boolean reverse = random().nextBoolean();
950918
final SortField sortField = LongField.newSortField("my_field", reverse, type);
951-
sortField.setOptimizeSortWithIndexedData(false);
952-
final Sort sort = new Sort(sortField); // sort without sort optimization
953-
final SortField sortField2 = LongField.newSortField("my_field", reverse, type);
954-
final Sort sort2 = new Sort(sortField2); // sort with sort optimization
955-
956-
long expectedCollectedHits = 0;
957-
long collectedHits = 0;
958-
long collectedHits2 = 0;
919+
final Sort sort = new Sort(sortField); // sort with sort optimization
920+
959921
int visitedHits = 0;
960922
FieldDoc after = null;
961923
while (visitedHits < numDocs) {
@@ -965,30 +927,14 @@ public void testSortOptimizationOnSortedNumericField() throws IOException {
965927
TopDocs topDocs = assertSearchHits(reader, sort, batch, after);
966928
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
967929

968-
TopDocs topDocs2 = assertSearchHits(reader, sort2, batch, after);
969-
ScoreDoc[] scoreDocs2 = topDocs2.scoreDocs;
970-
971-
// assert that the resulting hits are the same
972930
assertEquals(expectedHits, topDocs.scoreDocs.length);
973-
assertEquals(topDocs.scoreDocs.length, topDocs2.scoreDocs.length);
974931
for (int i = 0; i < scoreDocs.length; i++) {
975-
FieldDoc fieldDoc = (FieldDoc) scoreDocs[i];
976-
FieldDoc fieldDoc2 = (FieldDoc) scoreDocs2[i];
977-
assertEquals(fieldDoc.fields[0], fieldDoc2.fields[0]);
978-
assertEquals(fieldDoc.doc, fieldDoc2.doc);
979932
visitedHits++;
980933
}
981934

982-
expectedCollectedHits += numDocs;
983-
collectedHits += topDocs.totalHits.value();
984-
collectedHits2 += topDocs2.totalHits.value();
985935
after = (FieldDoc) scoreDocs[expectedHits - 1];
986936
}
987937
assertEquals(visitedHits, numDocs);
988-
assertEquals(expectedCollectedHits, collectedHits);
989-
// assert that the second sort with optimization collected less or equal hits
990-
assertTrue(collectedHits >= collectedHits2);
991-
// System.out.println(expectedCollectedHits + "\t" + collectedHits + "\t" + collectedHits2);
992938

993939
reader.close();
994940
dir.close();
@@ -1099,7 +1045,7 @@ private void testStringSortOptimization(
10991045
final DirectoryReader reader = DirectoryReader.open(writer);
11001046
writer.close();
11011047
doTestStringSortOptimization(reader);
1102-
doTestStringSortOptimizationDisabled(reader);
1048+
11031049
reader.close();
11041050
dir.close();
11051051
}
@@ -1203,12 +1149,6 @@ private void testStringSortOptimizationFieldMissingInSegment(
12031149
"my_field", true, SortedSetSelector.Type.MIN, SortField.STRING_LAST);
12041150
Sort sort = new Sort(sortField);
12051151
TopDocs topDocs = assertSearchHits(reader, sort, numHits, null);
1206-
1207-
sortField.setOptimizeSortWithIndexedData(false);
1208-
sort = new Sort(sortField);
1209-
TopDocs unpruned = assertSearchHits(reader, sort, numHits, null);
1210-
1211-
CheckHits.checkEqual(MatchAllDocsQuery.INSTANCE, topDocs.scoreDocs, unpruned.scoreDocs);
12121152
}
12131153

12141154
{ // descending sort with missing-first: once the queue fills from the first segment,
@@ -1227,12 +1167,6 @@ private void testStringSortOptimizationFieldMissingInSegment(
12271167
"my_field", false, SortedSetSelector.Type.MIN, SortField.STRING_FIRST);
12281168
Sort sort = new Sort(sortField);
12291169
TopDocs topDocs = assertSearchHits(reader, sort, numHits, null);
1230-
1231-
sortField.setOptimizeSortWithIndexedData(false);
1232-
sort = new Sort(sortField);
1233-
TopDocs unpruned = assertSearchHits(reader, sort, numHits, null);
1234-
1235-
CheckHits.checkEqual(MatchAllDocsQuery.INSTANCE, topDocs.scoreDocs, unpruned.scoreDocs);
12361170
}
12371171

12381172
reader.close();
@@ -1342,20 +1276,6 @@ private void doTestStringSortOptimization(DirectoryReader reader) throws IOExcep
13421276
}
13431277
}
13441278

1345-
public void doTestStringSortOptimizationDisabled(DirectoryReader reader) throws IOException {
1346-
SortField sortField =
1347-
KeywordField.newSortField(
1348-
"my_field", false, SortedSetSelector.Type.MIN, SortField.STRING_LAST);
1349-
sortField.setOptimizeSortWithIndexedData(false);
1350-
1351-
Sort sort = new Sort(sortField);
1352-
final int numDocs = reader.numDocs();
1353-
final int numHits = 5;
1354-
1355-
TopDocs topDocs = assertSearchHits(reader, sort, numHits, null);
1356-
assertEquals(numDocs, topDocs.totalHits.value());
1357-
}
1358-
13591279
private TopDocs assertSort(DirectoryReader reader, Sort sort, int n, FieldDoc after)
13601280
throws IOException {
13611281
TopDocs topDocs = assertSearchHits(reader, sort, n, after);

0 commit comments

Comments
 (0)