cpoerschke commented on code in PR #2248: URL: https://github.com/apache/solr/pull/2248#discussion_r1488340137
########## solr/core/src/java/org/apache/solr/search/SolrMultiCollectorManager.java: ########## @@ -0,0 +1,150 @@ +/* + * 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.solr.search; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.CollectorManager; +import org.apache.lucene.search.FilterScorable; +import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.search.MultiCollector; +import org.apache.lucene.search.Scorable; +import org.apache.lucene.search.ScoreMode; + +/** + * A {@link CollectorManager} implements which wrap a set of {@link CollectorManager} as {@link + * MultiCollector} acts for {@link Collector}. + */ +public class SolrMultiCollectorManager + implements CollectorManager<SolrMultiCollectorManager.Collectors, Object[]> { + + private final CollectorManager<Collector, ?>[] collectorManagers; + + @SafeVarargs + @SuppressWarnings({"varargs", "unchecked"}) + public SolrMultiCollectorManager( + final CollectorManager<? extends Collector, ?>... collectorManagers) { + if (collectorManagers.length < 1) { + throw new IllegalArgumentException("There must be at least one collector"); + } + this.collectorManagers = (CollectorManager[]) collectorManagers; + } + + @Override + public Collectors newCollector() throws IOException { + return new Collectors(); + } + + @Override + public Object[] reduce(Collection<Collectors> reducableCollectors) throws IOException { + final int size = reducableCollectors.size(); + final Object[] results = new Object[collectorManagers.length]; + for (int i = 0; i < collectorManagers.length; i++) { + final List<Collector> reducableCollector = new ArrayList<>(size); + for (Collectors collectors : reducableCollectors) + reducableCollector.add(collectors.collectors[i]); + results[i] = collectorManagers[i].reduce(reducableCollector); + } + return results; + } + + /** Wraps multiple collectors for processing */ + public class Collectors implements Collector { Review Comment: > not sure yet if these inner classes need to be public. https://github.com/apache/solr/pull/2248/commits/3e66068f1405ed36a2c45dc529645706d9fec0ea to reduce visibility -- `implements CollectorManager<SolrMultiCollectorManager.Collectors, Object[]>` says `SolrMultiCollectorManager.Collectors has private access in SolrMultiCollectorManager` if it's private but package visibility is okay and `LeafCollectors` can be private. -- 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...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org