use of com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager in project nrtsearch by Yelp.
the class SearchCollectorManager method reduce.
@Override
public SearcherResult reduce(Collection<SearchCollector> collectors) throws IOException {
Collection<Collector> subCollectors = new ArrayList<>(collectors.size());
for (SearchCollector searchCollector : collectors) {
subCollectors.add(searchCollector.hitCollector);
}
// We must cast the CollectorManager to use the concrete Collector type. This will be
// safe since the Collector object will be the one returned from the manager's
// newCollector() method.
@SuppressWarnings("unchecked") TopDocs hits = ((CollectorManager<Collector, ? extends TopDocs>) docCollectorManger).reduce(subCollectors);
Map<String, CollectorResult> collectorResults;
if (collectorManagers.isEmpty()) {
collectorResults = Collections.emptyMap();
} else {
collectorResults = new HashMap<>();
for (int i = 0; i < collectorManagers.size(); ++i) {
subCollectors.clear();
for (SearchCollector searchCollector : collectors) {
subCollectors.add(searchCollector.additionalCollectors.get(i));
}
AdditionalCollectorManager<? extends Collector, ? extends CollectorResult> cm = collectorManagers.get(i);
// We must cast the CollectorManager to use the concrete Collector type. See above comment.
@SuppressWarnings("unchecked") CollectorResult result = ((AdditionalCollectorManager<Collector, ? extends CollectorResult>) cm).reduce(subCollectors);
collectorResults.put(cm.getName(), result);
}
}
return new SearcherResult(hits, collectorResults);
}
use of com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager in project nrtsearch by Yelp.
the class SearchRequestProcessor method buildDocCollector.
/**
* Build {@link DocCollector} to provide the {@link org.apache.lucene.search.CollectorManager} for
* collecting hits for this query.
*
* @return collector
*/
private static DocCollector buildDocCollector(CollectorCreatorContext collectorCreatorContext) {
SearchRequest searchRequest = collectorCreatorContext.getRequest();
List<AdditionalCollectorManager<? extends Collector, ? extends CollectorResult>> additionalCollectors = searchRequest.getCollectorsMap().entrySet().stream().map(e -> CollectorCreator.getInstance().createCollectorManager(collectorCreatorContext, e.getKey(), e.getValue())).collect(Collectors.toList());
if (searchRequest.getQuerySort().getFields().getSortedFieldsList().isEmpty()) {
if (hasLargeNumHits(searchRequest)) {
return new LargeNumHitsCollector(collectorCreatorContext, additionalCollectors);
} else {
return new RelevanceCollector(collectorCreatorContext, additionalCollectors);
}
} else {
return new SortFieldCollector(collectorCreatorContext, additionalCollectors);
}
}
Aggregations