Module org.apache.lucene.monitor
Package org.apache.lucene.monitor
Class ParallelMatcher<T extends QueryMatch>
- java.lang.Object
-
- org.apache.lucene.monitor.CandidateMatcher<T>
-
- org.apache.lucene.monitor.ParallelMatcher<T>
-
- Type Parameters:
T
- the QueryMatch type returned
public class ParallelMatcher<T extends QueryMatch> extends CandidateMatcher<T>
Matcher class that runs matching queries in parallel.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.
- See Also:
PartitionMatcher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ParallelMatcher.MatcherTask
private class
ParallelMatcher.MatcherWorker
private static class
ParallelMatcher.ParallelMatcherFactory<T extends QueryMatch>
-
Field Summary
Fields Modifier and Type Field 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
-
Fields inherited from class org.apache.lucene.monitor.CandidateMatcher
searcher
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ParallelMatcher(IndexSearcher searcher, java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
Create a new ParallelMatcher
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFinish()
Called when all monitoring of a batch of documents is completestatic <T extends QueryMatch>
MatcherFactory<T>factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory)
Create a new MatcherFactory for a ParallelMatcherstatic <T extends QueryMatch>
MatcherFactory<T>factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
Create a new MatcherFactory for a ParallelMatcherprotected 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 hitsT
resolve(T match1, T match2)
If two matches from the same query are found (for example, two branches of a disjunction), combine them.-
Methods inherited from class org.apache.lucene.monitor.CandidateMatcher
addMatch, copyMatches, finish, reportError
-
-
-
-
Field Detail
-
queue
private final java.util.concurrent.BlockingQueue<ParallelMatcher.MatcherTask> queue
-
futures
private final java.util.List<java.util.concurrent.Future<CandidateMatcher<T extends QueryMatch>>> futures
-
collectorMatcher
private final CandidateMatcher<T extends QueryMatch> collectorMatcher
-
END
private static final ParallelMatcher.MatcherTask END
-
-
Constructor Detail
-
ParallelMatcher
private ParallelMatcher(IndexSearcher searcher, java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
Create a new ParallelMatcher- Parameters:
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 on
-
-
Method Detail
-
matchQuery
protected void matchQuery(java.lang.String queryId, Query matchQuery, java.util.Map<java.lang.String,java.lang.String> metadata) throws java.io.IOException
Description copied from class:CandidateMatcher
Runs the supplied query against this CandidateMatcher's set of documents, storing any resulting match, and recording the query in the presearcher hits- Specified by:
matchQuery
in classCandidateMatcher<T extends QueryMatch>
- Parameters:
queryId
- the query idmatchQuery
- the query to runmetadata
- the query metadata- Throws:
java.io.IOException
- on IO errors
-
resolve
public T resolve(T match1, T match2)
Description copied from class:CandidateMatcher
If two matches from the same query are found (for example, two branches of a disjunction), combine them.- Specified by:
resolve
in classCandidateMatcher<T extends QueryMatch>
- Parameters:
match1
- the first match foundmatch2
- the second match found- Returns:
- a Match object that combines the two
-
doFinish
protected void doFinish()
Description copied from class:CandidateMatcher
Called when all monitoring of a batch of documents is complete- Overrides:
doFinish
in classCandidateMatcher<T extends QueryMatch>
-
factory
public static <T extends QueryMatch> MatcherFactory<T> factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
Create a new MatcherFactory for a ParallelMatcher- Type Parameters:
T
- the type of QueryMatch generated- Parameters:
executor
- the ExecutorService to usematcherFactory
- the MatcherFactory to use to create submatchersthreads
- the number of threads to use
-
factory
public static <T extends QueryMatch> MatcherFactory<T> factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory)
Create a new MatcherFactory for a ParallelMatcherThis factory will create a ParallelMatcher that uses as many threads as there are cores available to the JVM (as determined by
Runtime.getRuntime().availableProcessors()
).- Type Parameters:
T
- the type of QueryMatch generated- Parameters:
executor
- the ExecutorService to usematcherFactory
- the MatcherFactory to use to create submatchers
-
-