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 `ParallelMatcher` can outweigh the benefit of multithreading.

  See Also:
    `ParallelMatcher`

- - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.monitor.CandidateMatcher

      `searcher`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doFinish()` Called when all monitoring of a batch of documents is complete
    `static <T extends QueryMatch> MatcherFactory<T>` | `factory(ExecutorService executor, MatcherFactory<T> matcherFactory)` Create a new MatcherFactory for a PartitionMatcher
    `static <T extends QueryMatch> MatcherFactory<T>` | `factory(ExecutorService executor, MatcherFactory<T> matcherFactory, int threads)` Create a new MatcherFactory for a PartitionMatcher
    `protected void` | `matchQuery(String queryId, Query matchQuery, Map<String,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.

    - ### Methods inherited from class org.apache.lucene.monitor.CandidateMatcher

      `addMatch, copyMatches`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### matchQuery

          protected void matchQuery(String queryId,
                                    Query matchQuery,
                                    Map<String,String> metadata)

      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 class `CandidateMatcher<T extends QueryMatch>`
      Parameters:
        `queryId` - the query id
        `matchQuery` - the query to run
        `metadata` - the query metadata

    - #### 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 class `CandidateMatcher<T extends QueryMatch>`
      Parameters:
        `match1` - the first match found
        `match2` - 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 class `CandidateMatcher<T extends QueryMatch>`

    - #### factory

          public static <T extends QueryMatch> MatcherFactory<T> factory(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 use
        `matcherFactory` - the MatcherFactory to use to create submatchers
        `threads` - the number of threads to use

    - #### factory

          public static <T extends QueryMatch> MatcherFactory<T> factory(ExecutorService executor,
                                                                         MatcherFactory<T> matcherFactory)

      Create a new MatcherFactory for a PartitionMatcher

      This 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 use
        `matcherFactory` - the MatcherFactory to use to create submatchers

Copyright © 2000-2022 Apache Software Foundation. All Rights Reserved.