msfroh commented on code in PR #13735: URL: https://github.com/apache/lucene/pull/13735#discussion_r1750940757
########## lucene/core/src/java/org/apache/lucene/search/CollectorManager.java: ########## @@ -46,4 +48,28 @@ public interface CollectorManager<C extends Collector, T> { * called after collection is finished on all provided collectors. */ T reduce(Collection<C> collectors) throws IOException; + + /** + * Wrap a provided {@link Collector} with a thin {@code CollectorManager} wrapper for use with + * {@link IndexSearcher#search(Query, CollectorManager)}. The wrapping {@code CollectorManager} + * provides no {@link CollectorManager#reduce(Collection)} implementation, so the wrapped {@code + * Collector} needs to do all relevant work while collecting. + * + * <p>Note: This is only safe to use when {@code IndexSearcher} is created with no executor (see: + * {@link IndexSearcher#IndexSearcher(IndexReader, Executor)}), or the provided collector is + * threadsafe. + */ + static <C extends Collector> CollectorManager<C, ?> wrap(C in) { + return new CollectorManager<C, Void>() { + @Override + public C newCollector() { + return in; + } + + @Override + public Void reduce(Collection<C> collectors) { + return null; Review Comment: Can we assume that the `Collector`s passed to `reduce` were produced by calling `newCollector` on this collector? If so, the assertion that `newCollector` was called at most once should be sufficient. -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org