Skip to content

Apache Lucene open-source search software

Remove IndexSearcher#search(List<LeafReaderContext>, Weight, Collector) (#13780)

Luca Cavannaf778cc49246f
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index aa00fbfbfaa..eda8389b550 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -120,6 +120,9 @@ API Changes
* GITHUB#13328: Convert many basic Lucene classes to record classes, including CollectionStatistics, TermStatistics and LeafMetadata. (Shubham Chaudhary)
+* GITHUB#13780: Remove `IndexSearcher#search(List<LeafReaderContext>, Weight, Collector)` in favour of the newly
+ introduced `IndexSearcher#search(LeafReaderContextPartition[], Weight, Collector)`
+
New Features
---------------------
diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md
index 8cf9c299b29..fd3ea7e5be5 100644
--- a/lucene/MIGRATE.md
+++ b/lucene/MIGRATE.md
@@ -859,7 +859,7 @@ Subclasses of `IndexSearcher` that call or override the `searchLeaf` method need
### Signature of static IndexSearch#slices method changed
-The static `IndexSearcher#sslices(List<LeafReaderContext> leaves, int maxDocsPerSlice, int maxSegmentsPerSlice)`
+The static `IndexSearcher#slices(List<LeafReaderContext> leaves, int maxDocsPerSlice, int maxSegmentsPerSlice)`
method now supports an additional 4th and last argument to optionally enable creating segment partitions:
`IndexSearcher#slices(List<LeafReaderContext> leaves, int maxDocsPerSlice, int maxSegmentsPerSlice, boolean allowSegmentPartitions)`
@@ -868,3 +868,9 @@ method now supports an additional 4th and last argument to optionally enable cre
`TotalHitCountCollectorManager` now requires that an array of `LeafSlice`s, retrieved via `IndexSearcher#getSlices`,
is provided to its constructor. Depending on whether segment partitions are present among slices, the manager can
optimize the type of collectors it creates and exposes via `newCollector`.
+
+### `IndexSearcher#search(List<LeafReaderContext>, Weight, Collector)` removed
+
+The protected `IndexSearcher#search(List<LeafReaderContext> leaves, Weight weight, Collector collector)` method has been
+removed in favour of the newly introduced `search(LeafReaderContextPartition[] partitions, Weight weight, Collector collector)`.
+`IndexSearcher` subclasses that override this method need to instead override the new method.
\ No newline at end of file
diff --git a/lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java b/lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java
index 89f14fff20b..9a21c882052 100644
--- a/lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java
+++ b/lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java
@@ -21,8 +21,8 @@ package org.apache.lucene.search;
* the current leaf.
*
* <p>Note: IndexSearcher swallows this exception and never re-throws it. As a consequence, you
- * should not catch it when calling {@link IndexSearcher#search} as it is unnecessary and might hide
- * misuse of this exception.
+ * should not catch it when calling the different search methods that {@link IndexSearcher} exposes
+ * as it is unnecessary and might hide misuse of this exception.
*/
@SuppressWarnings("serial")
public final class CollectionTerminatedException extends RuntimeException {
diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
index 2a810e674e9..aad2ac43edb 100644
--- a/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
+++ b/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
@@ -134,7 +134,8 @@ public abstract class FieldComparator<T> {
/**
* Sorts by descending relevance. NOTE: if you are sorting only by descending relevance and then
* secondarily by ascending docID, performance is faster using {@link TopScoreDocCollector}
- * directly (which {@link IndexSearcher#search} uses when no {@link Sort} is specified).
+ * directly (which {@link IndexSearcher#search(Query, int)} uses when no {@link Sort} is
+ * specified).
*/
public static final class RelevanceComparator extends FieldComparator<Float>
implements LeafFieldComparator {
diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
index cc566a8c41e..9c7274da3eb 100644
--- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
+++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
@@ -606,9 +606,13 @@ public class IndexSearcher {
* CollectorManager)} due to its support for concurrency in IndexSearcher
*/
@Deprecated
- public void search(Query query, Collector results) throws IOException {
- query = rewrite(query, results.scoreMode().needsScores());
- search(leafContexts, createWeight(query, results.scoreMode(), 1), results);
+ public void search(Query query, Collector collector) throws IOException {
+ query = rewrite(query, collector.scoreMode().needsScores());
+ Weight weight = createWeight(query, collector.scoreMode(), 1);
+ collector.setWeight(weight);
+ for (LeafReaderContext ctx : leafContexts) { // search each subreader
+ searchLeaf(ctx, 0, DocIdSetIterator.NO_MORE_DOCS, weight, collector);
+ }
}
/** Returns true if any search hit the {@link #setTimeout(QueryTimeout) timeout}. */
@@ -785,38 +789,6 @@ public class IndexSearcher {
}
}
- /**
- * Lower-level search API.
- *
- * <p>{@link #searchLeaf(LeafReaderContext, int, int, Weight, Collector)} is called for every leaf
- * partition. <br>
- *
- * <p>NOTE: this method executes the searches on all given leaves exclusively. To search across
- * all the searchers leaves use {@link #leafContexts}.
- *
- * @param leaves the searchers leaves to execute the searches on
- * @param weight to match documents
- * @param collector to receive hits
- * @throws TooManyClauses If a query would exceed {@link IndexSearcher#getMaxClauseCount()}
- * clauses.
- * @deprecated in favour of {@link #search(LeafReaderContextPartition[], Weight, Collector)} that
- * provides the same functionality while also supporting segments partitioning. Will be
- * removed once the removal of the deprecated {@link #search(Query, Collector)} is completed.
- */
- @Deprecated
- protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector)
- throws IOException {
-
- collector.setWeight(weight);
-
- // TODO: should we make this
- // threaded...? the Collector could be sync'd?
- // always use single thread:
- for (LeafReaderContext ctx : leaves) { // search each subreader
- searchLeaf(ctx, 0, DocIdSetIterator.NO_MORE_DOCS, weight, collector);
- }
- }
-
/**
* Lower-level search API
*
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
index eaf75e99eb6..74205522451 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java
@@ -1659,10 +1659,11 @@ public class TestDrillSideways extends FacetTestCase {
}
@Override
- protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector)
+ protected void search(
+ LeafReaderContextPartition[] partitions, Weight weight, Collector collector)
throws IOException {
AssertingCollector assertingCollector = AssertingCollector.wrap(collector);
- super.search(leaves, weight, assertingCollector);
+ super.search(partitions, weight, assertingCollector);
assert assertingCollector.hasFinishedCollectingPreviousLeaf;
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingIndexSearcher.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingIndexSearcher.java
index 431871e1762..8c8b35f596c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingIndexSearcher.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingIndexSearcher.java
@@ -17,12 +17,10 @@
package org.apache.lucene.tests.search;
import java.io.IOException;
-import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
-import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -71,15 +69,6 @@ public class AssertingIndexSearcher extends IndexSearcher {
return rewritten;
}
- @Override
- protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector)
- throws IOException {
- assert weight instanceof AssertingWeight;
- AssertingCollector assertingCollector = AssertingCollector.wrap(collector);
- super.search(leaves, weight, assertingCollector);
- assert assertingCollector.hasFinishedCollectingPreviousLeaf;
- }
-
@Override
protected void search(LeafReaderContextPartition[] leaves, Weight weight, Collector collector)
throws IOException {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/CheckHits.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/CheckHits.java
index 6fa443bc325..5a2611da2e2 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/CheckHits.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/CheckHits.java
@@ -554,9 +554,9 @@ public class CheckHits {
}
@Override
- public void search(Query query, Collector results) throws IOException {
+ public void search(Query query, Collector collector) throws IOException {
checkExplanations(query);
- super.search(query, results);
+ super.search(query, collector);
}
@Override