T
- the QueryMatch type returnedpublic class ParallelMatcher<T extends QueryMatch> extends CandidateMatcher<T>
This class delegates the actual matching to separate CandidateMatcher classes, built from a passed in MatcherFactory.
Use this when individual queries can take a long time to run, and you want to minimize latency. The matcher distributes queries amongst its worker threads using a BlockingQueue, and synchronization overhead may affect performance if the individual queries are very fast.
PartitionMatcher
Modifier and Type | Class and Description |
---|---|
private static class |
ParallelMatcher.MatcherTask |
private class |
ParallelMatcher.MatcherWorker |
private static class |
ParallelMatcher.ParallelMatcherFactory<T extends QueryMatch> |
Modifier and Type | Field and Description |
---|---|
private CandidateMatcher<T> |
collectorMatcher |
private static ParallelMatcher.MatcherTask |
END |
private java.util.List<java.util.concurrent.Future<CandidateMatcher<T>>> |
futures |
private java.util.concurrent.BlockingQueue<ParallelMatcher.MatcherTask> |
queue |
searcher
Modifier | Constructor and Description |
---|---|
private |
ParallelMatcher(IndexSearcher searcher,
java.util.concurrent.ExecutorService executor,
MatcherFactory<T> matcherFactory,
int threads)
Create a new ParallelMatcher
|
Modifier and Type | Method and Description |
---|---|
protected void |
doFinish()
Called when all monitoring of a batch of documents is complete
|
static <T extends QueryMatch> |
factory(java.util.concurrent.ExecutorService executor,
MatcherFactory<T> matcherFactory)
Create a new MatcherFactory for a ParallelMatcher
|
static <T extends QueryMatch> |
factory(java.util.concurrent.ExecutorService executor,
MatcherFactory<T> matcherFactory,
int threads)
Create a new MatcherFactory for a ParallelMatcher
|
protected void |
matchQuery(java.lang.String queryId,
Query matchQuery,
java.util.Map<java.lang.String,java.lang.String> metadata)
Runs the supplied query against this CandidateMatcher's set of documents, storing any
resulting match, and recording the query in the presearcher hits
|
T |
resolve(T match1,
T match2)
If two matches from the same query are found (for example, two branches of a disjunction),
combine them.
|
addMatch, copyMatches, finish, reportError
private final java.util.concurrent.BlockingQueue<ParallelMatcher.MatcherTask> queue
private final java.util.List<java.util.concurrent.Future<CandidateMatcher<T extends QueryMatch>>> futures
private final CandidateMatcher<T extends QueryMatch> collectorMatcher
private static final ParallelMatcher.MatcherTask END
private ParallelMatcher(IndexSearcher searcher, java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
searcher
- the IndexSearcher to match againstexecutor
- an ExecutorService to use for parallel executionmatcherFactory
- MatcherFactory to use to create CandidateMatchersthreads
- the number of threads to execute onprotected void matchQuery(java.lang.String queryId, Query matchQuery, java.util.Map<java.lang.String,java.lang.String> metadata) throws java.io.IOException
CandidateMatcher
matchQuery
in class CandidateMatcher<T extends QueryMatch>
queryId
- the query idmatchQuery
- the query to runmetadata
- the query metadatajava.io.IOException
- on IO errorspublic T resolve(T match1, T match2)
CandidateMatcher
resolve
in class CandidateMatcher<T extends QueryMatch>
match1
- the first match foundmatch2
- the second match foundprotected void doFinish()
CandidateMatcher
doFinish
in class CandidateMatcher<T extends QueryMatch>
public static <T extends QueryMatch> MatcherFactory<T> factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
T
- the type of QueryMatch generatedexecutor
- the ExecutorService to usematcherFactory
- the MatcherFactory to use to create submatchersthreads
- the number of threads to usepublic static <T extends QueryMatch> MatcherFactory<T> factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory)
This factory will create a ParallelMatcher that uses as many threads as there are cores available
to the JVM (as determined by Runtime.getRuntime().availableProcessors()
).
T
- the type of QueryMatch generatedexecutor
- the ExecutorService to usematcherFactory
- the MatcherFactory to use to create submatchers