Skip to content
Open
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
11 changes: 9 additions & 2 deletions lucene/monitor/src/java/org/apache/lucene/monitor/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.LeafReader;
Expand All @@ -48,6 +49,8 @@ public class Monitor implements Closeable {

private final long commitBatchSize;

private final Executor executor;

/**
* Create a non-persistent Monitor instance with the default term-filtering Presearcher
*
Expand Down Expand Up @@ -96,6 +99,7 @@ public Monitor(Analyzer analyzer, Presearcher presearcher, MonitorConfiguration
}

this.commitBatchSize = configuration.getQueryUpdateBufferSize();
this.executor = configuration.getExecutor();
}

/**
Expand Down Expand Up @@ -219,7 +223,9 @@ public <T extends QueryMatch> MultiMatchingQueries<T> match(
Document[] docs, MatcherFactory<T> factory) throws IOException {
try (DocumentBatch batch = DocumentBatch.of(analyzer, docs)) {
LeafReader reader = batch.get();
CandidateMatcher<T> matcher = factory.createMatcher(new IndexSearcher(batch.get()));
IndexSearcher indexSearcher =
(executor != null) ? new IndexSearcher(reader, executor) : new IndexSearcher(reader);
CandidateMatcher<T> matcher = factory.createMatcher(indexSearcher);
StandardQueryCollector<T> collector = new StandardQueryCollector<>(matcher);
long buildTime = queryIndex.search(t -> presearcher.buildQuery(reader, t), collector);
return matcher.finish(buildTime, collector.queryCount);
Expand Down Expand Up @@ -318,7 +324,8 @@ public <T extends QueryMatch> PresearcherMatches<T> debug(
Document[] docs, MatcherFactory<T> factory) throws IOException {
try (DocumentBatch batch = DocumentBatch.of(analyzer, docs)) {
LeafReader reader = batch.get();
IndexSearcher searcher = new IndexSearcher(reader);
IndexSearcher searcher =
(executor != null) ? new IndexSearcher(reader, executor) : new IndexSearcher(reader);
searcher.setQueryCache(null);
PresearcherQueryCollector<T> collector =
new PresearcherQueryCollector<>(factory.createMatcher(searcher));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.index.IndexWriter;
Expand All @@ -39,6 +40,7 @@ public class MonitorConfiguration {
private MonitorQuerySerializer serializer;
private boolean readOnly = false;
private IOSupplier<Directory> directoryProvider = () -> new ByteBuffersDirectory();
private Executor executor = null;

private static IndexWriterConfig defaultIndexWriterConfig() {
IndexWriterConfig iwc = new IndexWriterConfig(new KeywordAnalyzer());
Expand Down Expand Up @@ -165,4 +167,25 @@ public MonitorConfiguration setQueryUpdateBufferSize(int size) {
public int getQueryUpdateBufferSize() {
return queryUpdateBufferSize;
}

/**
* Set the Executor to use for concurrent search.
*
* <p>If set, the Monitor will pass this Executor to the IndexSearcher it creates internally,
* allowing for inter-segment concurrency in search operations.
*
* @param executor the Executor to use for concurrent search
* @return the current configuration
*/
public MonitorConfiguration setExecutor(Executor executor) {
this.executor = executor;
return this;
}

/**
* @return the Executor used for concurrent search, or null if not set
*/
public Executor getExecutor() {
return executor;
}
}
Loading