Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of IndexSearcher#Search(Query, Collector) from monitor package #13735

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ API Changes
* GITHUB#13568: Add DrillSideways#search method that supports any CollectorManagers for drill-sideways dimensions
or drill-down. (Egor Potemkin)

* GITHUB#13735: Add CollectorManager#forSequentialExecution to make CollectorManager creation more convenient
for users of the deprecated IndexSearcher#search(Query, Collector). (Greg Miller)

New Features
---------------------

Expand Down Expand Up @@ -348,6 +351,9 @@ Improvements

* GITHUB#13201: Better cost estimation on MultiTermQuery over few terms. (Michael Froh)

* GITHUB#13735: Migrate monitor package usage of deprecated IndexSearcher#search(Query, Collector)
to IndexSearcher#search(Query, CollectorManager). (Greg Miller)

Optimizations
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Executor;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;

/**
Expand Down Expand Up @@ -53,4 +55,36 @@ public interface CollectorManager<C extends Collector, T> {
* called after collection is finished on all provided collectors.
*/
T reduce(Collection<C> collectors) throws IOException;

/**
* Wrap a provided {@link Collector} with a thin {@code CollectorManager} wrapper for use with
* {@link IndexSearcher#search(Query, CollectorManager)} when doing single-threaded searching. The
* wrapping {@code CollectorManager} provides no {@link CollectorManager#reduce(Collection)}
* implementation, so the wrapped {@code Collector} needs to do all relevant work while
* collecting.
*
* <p>Note: This is only safe to use when {@code IndexSearcher} is created with no executor (see:
* {@link IndexSearcher#IndexSearcher(IndexReader, Executor)}).
*/
static <C extends Collector> CollectorManager<C, ?> forSequentialExecution(C in) {
return new CollectorManager<C, Void>() {
private boolean newCollectorInvoked;

@Override
public C newCollector() {
if (newCollectorInvoked) {
throw new IllegalStateException(
"newCollector should be invoked at most once. Ensure your IndexSearcher has been created without an Executor.");
}
newCollectorInvoked = true;
return in;
javanna marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Void reduce(Collection<C> collectors) {
assert collectors.size() == 1 : "collectors should contain exactly one collector instance";
return null;
javanna marked this conversation as resolved.
Show resolved Hide resolved
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.Map;
import org.apache.lucene.search.CollectorManager;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
Expand All @@ -37,7 +38,9 @@ abstract class CollectingMatcher<T extends QueryMatch> extends CandidateMatcher<
@Override
public void matchQuery(final String queryId, Query matchQuery, Map<String, String> metadata)
throws IOException {
searcher.search(matchQuery, new MatchCollector(queryId, scoreMode));
searcher.search(
matchQuery,
CollectorManager.forSequentialExecution(new MatchCollector(queryId, scoreMode)));
}

/**
Expand Down