bjacobowitz commented on PR #13109:
URL: https://github.com/apache/lucene/pull/13109#issuecomment-2250901342
Sure. It's roughly the same approach as ParallelMatcher, but with a reactive
setup instead of an ExecutorService.
`monitor.match(Document, MatcherFactory)` runs a bunch of queries with a
`CandidateMatcher` from `MatcherFactory` and returns `MatchingQueries`, but it
won't return results until all the queries have run. I am trying to create a
custom `CandidateMatcher` (and a factory to wrap it) that delegates to an
existing matcher to do the matching work, but puts its results into a Flux, so
that I can start processing the individual results as soon as they are
available.
It's something sort of like this:
```java
package com.my.custom.package;
public class MyReactiveMatcher<T extends QueryMatch> extends
CandidateMatcher<T> {
public static class MatchTask {
final String queryId;
final Query matchQuery;
final Map<String, String> metadata;
public MatchTask(String queryId, Query matchQuery, Map<String, String>
metadata) {
this.queryId = queryId;
this.matchQuery = matchQuery;
this.metadata = metadata;
}
}
private final List<MatchTask> tasks = new ArrayList<>();
// Factory of CandidateMatcher to which we will delegate matching
private final MatcherFactory<T> factory;
public MyReactiveMatcher(IndexSearcher searcher, MatcherFactory<T>
factory) {
super(searcher);
this.factory = factory;
}
@Override
public void matchQuery(String queryId, Query matchQuery, Map<String,
String> metadata) {
// Register a query to try to match later
tasks.add(new MatchTask(queryId, matchQuery, metadata));
}
// Run matchQuery
private static <T extends QueryMatch> MultiMatchingQueries<U> getResult(
MatchTask task, CandidateMatcher<T> matcher) {
try {
// This call is not possible outside the lucene.monitor package:
matcher.matchQuery(task.queryId, task.matchQuery, task.metadata);
} catch (IOException e) {
// This call is not possible outside the lucene.monitor package:
matcher.reportError(task.queryId, e);
}
// This call is not possible outside the lucene.monitor package:
return matcher.finish(0, 0);
}
@Override
protected void doFinish() {
// Kick off matching, with results coming back through the Flux as they
are finished
Flux.fromIterable(tasks).flatMap(t -> getResult(t,
factory.createMatcher(searcher))).doOnNext(::aBunchOfStuff).subscribe();
}
```
The `getResult` function is where the issue comes up. I can't really make
use of the CandidateMatcher generated by the factory if I'm outside of the
`lucene.monitor` package, due to the access protections in place.
To use your suggestion of a subclass, I could create a `MyReactiveMatcher`
with a factory that returns my custom subclass of `CandidateMatcher` (then I
could just cast to it and call extra its functions), but to be able to create
that custom subclass in the first place I would need to extend a concrete
implementation of `CandidateMatcher`, and there really aren't any available at
the moment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]