Skip to content

Commit

Permalink
Javadoc for WrappedCandidateMatcher and WrappedMatcherFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
bjacobowitz committed Feb 15, 2024
1 parent 6ed8241 commit df1797a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,92 @@
import java.util.Map;
import org.apache.lucene.search.Query;

// Wrapper class for an existing candidate matcher exposing finish, matchQuery and reportError
// for composition of matchers
/**
* Wrapper class for an existing candidate matcher exposing finish, matchQuery and reportError for
* composition of matchers
*/
public class WrappedCandidateMatcher<T extends QueryMatch> {

private CandidateMatcher<T> delegateTo;

/**
* Creates a new WrappedCandidateMatcher delegating to the supplied CandidateMatcher
*
* @param wrapThis the CandidateMatcher to which functions should be delegate
*/
public WrappedCandidateMatcher(CandidateMatcher<T> wrapThis) {
delegateTo = wrapThis;
}

/**
* Runs the supplied query against the delegate CandidateMatcher's set of documents, storing any
* resulting match, and recording the query in the presearcher hits
*
* @param queryId the query id
* @param matchQuery the query to run
* @param metadata the query metadata
* @throws IOException on IO errors
*/
public void matchQuery(String queryId, Query matchQuery, Map<String, String> metadata)
throws IOException {
delegateTo.matchQuery(queryId, matchQuery, metadata);
}

/**
* @return the matches from this matcher
*/
public MultiMatchingQueries<T> finish(long buildTime, int queryCount) {
return delegateTo.finish(buildTime, queryCount);
}

/**
* Record a match into delegate
*
* @param match a QueryMatch object
*/
protected void addMatch(T match, int doc) {
delegateTo.addMatch(match, doc);
}

/**
* If two matches from the same query are found (for example, two branches of a disjunction),
* combine them using the delegate's resolve function.
*
* @param match1 the first match found
* @param match2 the second match found
* @return a Match object that combines the two
*/
public T resolve(T match1, T match2) {
return delegateTo.resolve(match1, match2);
}

/** If running a query throws an Exception, this function will add error into delegate */
public void reportError(String queryId, Exception e) {
delegateTo.reportError(queryId, e);
}

/** Called when all monitoring of a batch of documents is complete */
protected void doFinish() {
delegateTo.doFinish();
}

/** Copy all matches from another CandidateMatcher */
protected void copyMatches(CandidateMatcher<T> other) {
delegateTo.copyMatches(other);
}

/**
* Build a MultiMatchingQueries
*
* @param matches the matches to include, mapping from queryId to match
* @param errors any errors thrown while evaluating matches
* @param queryBuildTime how long (in ns) it took to build the Presearcher query for the matcher
* run
* @param searchTime how long (in ms) it took to run the selected queries
* @param queriesRun the number of queries passed to this CandidateMatcher during the matcher run
* @param batchSize the number of documents in the batch
* @return a MultiMatchingQueries object with the results of matching a batch of Documents
*/
public static <T1 extends QueryMatch> MultiMatchingQueries<T1> buildMultiMatchingQueries(
List<Map<String, T1>> matches,
Map<String, Exception> errors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@

import org.apache.lucene.search.IndexSearcher;

/**
* Interface for the creation of new WrappedCandidateMatcher objects
*
* @param <T> a subclass of {@link CandidateMatcher}
*/
public interface WrappedMatcherFactory<T extends QueryMatch> {

/**
* Create a new {@link WrappedCandidateMatcher} object, to be used to select queries to match
* against the passed-in IndexSearcher
*/
WrappedCandidateMatcher<T> createWrappedMatcher(IndexSearcher searcher);
}

0 comments on commit df1797a

Please sign in to comment.