Skip to content

Apache Lucene open-source search software

Remove deprecated usages of search(Query, Collector) from monitor module (#16197)

Luca Cavanna3798b540a743
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4912aa5e01f..31d20695536 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -610,6 +610,8 @@ Other
* GITHUB#16178: Simplify how we collect hits in the LRU cache from a DocIdStream into a RoaringDocIdSet.
(Ignacio Vera)
+* GITHUB#16197: Remove deprecated usages of search(Query, Collector) from monitor module. (Luca Cavanna)
+
======================= Lucene 10.4.0 =======================
API Changes
diff --git a/lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java b/lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
index 35a8e069821..1a7891c8d80 100644
--- a/lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
+++ b/lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
@@ -18,10 +18,12 @@
package org.apache.lucene.monitor;
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.search.CollectorManager;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
@@ -79,7 +81,21 @@ class ReadonlyQueryIndex extends QueryIndex {
queryBuilder.buildQuery(
termFilters.get(searcher.getIndexReader().getReaderCacheHelper().getKey()));
buildTime = System.nanoTime() - buildTime;
- searcher.search(query, collector);
+ searcher.search(
+ query,
+ new CollectorManager<LazyMonitorQueryCollector, Void>() {
+ @Override
+ public LazyMonitorQueryCollector newCollector() {
+ return collector;
+ }
+
+ @Override
+ public Void reduce(Collection<LazyMonitorQueryCollector> collectors) {
+ assert collectors.size() == 1
+ : "QueryCollector needs to be made thread-safe before an executor can be provided to the index searcher used by monitor";
+ return null;
+ }
+ });
return buildTime;
} finally {
if (searcher != null) {
diff --git a/lucene/monitor/src/java/org/apache/lucene/monitor/WritableQueryIndex.java b/lucene/monitor/src/java/org/apache/lucene/monitor/WritableQueryIndex.java
index 8c5fe84b632..367de7653a6 100644
--- a/lucene/monitor/src/java/org/apache/lucene/monitor/WritableQueryIndex.java
+++ b/lucene/monitor/src/java/org/apache/lucene/monitor/WritableQueryIndex.java
@@ -19,6 +19,7 @@ package org.apache.lucene.monitor;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -38,6 +39,7 @@ import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.CollectorManager;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
@@ -220,7 +222,21 @@ class WritableQueryIndex extends QueryIndex {
queryBuilder.buildQuery(
termFilters.get(searcher.getIndexReader().getReaderCacheHelper().getKey()));
buildTime = System.nanoTime() - buildTime;
- searcher.search(query, collector);
+ searcher.search(
+ query,
+ new CollectorManager<MonitorQueryCollector, Void>() {
+ @Override
+ public MonitorQueryCollector newCollector() {
+ return collector;
+ }
+
+ @Override
+ public Void reduce(Collection<MonitorQueryCollector> collectors) {
+ assert collectors.size() == 1
+ : "QueryCollector needs to be made thread-safe before an executor can be provided to the index searcher used by monitor";
+ return null;
+ }
+ });
return buildTime;
} finally {
if (searcher != null) {