Package org.apache.lucene.monitor
Class PartitionMatcher<T extends QueryMatch>
- java.lang.Object
-
- org.apache.lucene.monitor.CandidateMatcher<T>
-
- org.apache.lucene.monitor.PartitionMatcher<T>
-
- Type Parameters:
T- the type of QueryMatch to return
public class PartitionMatcher<T extends QueryMatch> extends CandidateMatcher<T>
A multi-threaded matcher that collects all possible matches in one pass, and then partitions them amongst a number of worker threads to perform the actual matching.This class delegates the matching to separate CandidateMatcher classes, built from a passed in MatcherFactory.
Use this if your query sets contain large numbers of very fast queries, where the synchronization overhead of
ParallelMatchercan outweigh the benefit of multithreading.- See Also:
ParallelMatcher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPartitionMatcher.MatcherWorkerprivate static classPartitionMatcher.MatchTaskprivate static classPartitionMatcher.PartitionMatcherFactory<T extends QueryMatch>
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ExecutorServiceexecutorprivate MatcherFactory<T>matcherFactoryprivate CandidateMatcher<T>resolvingMatcherprivate java.util.List<PartitionMatcher.MatchTask>tasksprivate intthreads-
Fields inherited from class org.apache.lucene.monitor.CandidateMatcher
searcher
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePartitionMatcher(IndexSearcher searcher, java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoFinish()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 PartitionMatcherstatic <T extends QueryMatch>
MatcherFactory<T>factory(java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)Create a new MatcherFactory for a PartitionMatcherprotected voidmatchQuery(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(package private) static <T> java.util.List<java.util.List<T>>partition(java.util.List<T> items, int slices)Tresolve(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
-
executor
private final java.util.concurrent.ExecutorService executor
-
matcherFactory
private final MatcherFactory<T extends QueryMatch> matcherFactory
-
threads
private final int threads
-
resolvingMatcher
private final CandidateMatcher<T extends QueryMatch> resolvingMatcher
-
tasks
private final java.util.List<PartitionMatcher.MatchTask> tasks
-
-
Constructor Detail
-
PartitionMatcher
private PartitionMatcher(IndexSearcher searcher, java.util.concurrent.ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)
-
-
Method Detail
-
matchQuery
protected void matchQuery(java.lang.String queryId, Query matchQuery, java.util.Map<java.lang.String,java.lang.String> metadata)Description copied from class:CandidateMatcherRuns the supplied query against this CandidateMatcher's set of documents, storing any resulting match, and recording the query in the presearcher hits- Specified by:
matchQueryin classCandidateMatcher<T extends QueryMatch>- Parameters:
queryId- the query idmatchQuery- the query to runmetadata- the query metadata
-
resolve
public T resolve(T match1, T match2)
Description copied from class:CandidateMatcherIf two matches from the same query are found (for example, two branches of a disjunction), combine them.- Specified by:
resolvein 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:CandidateMatcherCalled when all monitoring of a batch of documents is complete- Overrides:
doFinishin 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 PartitionMatcher- 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 PartitionMatcherThis factory will create a PartitionMatcher 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
-
partition
static <T> java.util.List<java.util.List<T>> partition(java.util.List<T> items, int slices)
-
-