org.opensearch.search.query.MultiCollectorWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch Show documentation
Show all versions of opensearch Show documentation
OpenSearch subproject :server
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.search.query;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.ScoreMode;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* Wraps MultiCollector and provide access to underlying collectors.
* Please check out https://github.com/apache/lucene/pull/455.
*
* @opensearch.internal
*/
public class MultiCollectorWrapper implements Collector {
private final MultiCollector delegate;
private final Collection collectors;
MultiCollectorWrapper(MultiCollector delegate, Collection collectors) {
this.delegate = delegate;
this.collectors = collectors;
}
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
return delegate.getLeafCollector(context);
}
@Override
public ScoreMode scoreMode() {
return delegate.scoreMode();
}
public Collection getCollectors() {
return collectors;
}
public static Collector wrap(Collector... collectors) {
final List collectorsList = Arrays.asList(collectors);
final Collector collector = MultiCollector.wrap(collectorsList);
if (collector instanceof MultiCollector) {
return new MultiCollectorWrapper((MultiCollector) collector, collectorsList);
} else {
return collector;
}
}
}