epotyom commented on code in PR #13568: URL: https://github.com/apache/lucene/pull/13568#discussion_r1681768843
########## lucene/core/src/java/org/apache/lucene/search/CollectorOwner.java: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Like {@link CollectorManager}, but it owns the collectors its manager creates. It is convenient + * that clients of the class don't have to worry about keeping the list of collectors, as well as + * about making the collectors type (C) compatible when reduce is called. Instance of this class + * also caches results of {@link CollectorManager#reduce(Collection)}. + * + * <p>Note that instance of this class ignores any {@link Collector} created by {@link + * CollectorManager#newCollector()} directly, not through {@link #newCollector()} + * + * @lucene.experimental + */ +public final class CollectorOwner<C extends Collector, T> { Review Comment: The problem with using `CollectorManager` is that reduce method takes `Collection<C> collectors` as an argument. It means that users not only have to manage the list of collectors themselves, but also make sure that their `CollectorManager` and collection of `Collector`s are of the same type `C`. It becomes a problem for DrillSideways, where we want to use different `CollectorManager`s for different dimensions. In theory we can overcome that by keeping a list of types for dimensions, and cast Collectors' collection items to the right type before calling `#reduce`. But creating `CollectorOwner` class looks like better solution to me - it allows DrillSideways and IndexSearcher to be ignorant of collector's and result's types. As a bonus, it manages the list of Collectors for both `DrillSideways` and `IndexSearcher`. Please let me know if you think its not worth it - we can revisit the idea of keeping list of types in DrillSideways? -- 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