Search in sources :

Example 1 with AdditionalCollectorManager

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);
}
Also used : CollectorResult(com.yelp.nrtsearch.server.grpc.CollectorResult) ArrayList(java.util.ArrayList) AdditionalCollectorManager(com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager) CollectorManager(org.apache.lucene.search.CollectorManager) TopDocs(org.apache.lucene.search.TopDocs) AdditionalCollectorManager(com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager) LeafCollector(org.apache.lucene.search.LeafCollector) DocCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.DocCollector) Collector(org.apache.lucene.search.Collector)

Example 2 with AdditionalCollectorManager

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);
    }
}
Also used : SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) ScriptParamsUtils(com.yelp.nrtsearch.server.utils.ScriptParamsUtils) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager) Query(org.apache.lucene.search.Query) QueryRescorer(com.yelp.nrtsearch.server.grpc.QueryRescorer) PluginRescorer(com.yelp.nrtsearch.server.grpc.PluginRescorer) HashMap(java.util.HashMap) AdditionalCollectorManager(com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager) VirtualField(com.yelp.nrtsearch.server.grpc.VirtualField) CollectorCreator(com.yelp.nrtsearch.server.luceneserver.search.collectors.CollectorCreator) ArrayList(java.util.ArrayList) QueryBuilder(org.apache.lucene.util.QueryBuilder) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) VirtualFieldDef(com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef) IndexableFieldDef(com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef) Map(java.util.Map) DrillDownQuery(org.apache.lucene.facet.DrillDownQuery) ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) ScoreScript(com.yelp.nrtsearch.server.luceneserver.script.ScoreScript) DefaultSharedDocContext(com.yelp.nrtsearch.server.luceneserver.doc.DefaultSharedDocContext) SimpleQueryParser(org.apache.lucene.queryparser.simple.SimpleQueryParser) QueryParserBase(org.apache.lucene.queryparser.classic.QueryParserBase) CollectorResult(com.yelp.nrtsearch.server.grpc.CollectorResult) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) CollectorCreatorContext(com.yelp.nrtsearch.server.luceneserver.search.collectors.CollectorCreatorContext) RescoreTask(com.yelp.nrtsearch.server.luceneserver.rescore.RescoreTask) QueryNodeMapper(com.yelp.nrtsearch.server.luceneserver.QueryNodeMapper) QueryRescore(com.yelp.nrtsearch.server.luceneserver.rescore.QueryRescore) RescoreOperation(com.yelp.nrtsearch.server.luceneserver.rescore.RescoreOperation) DocCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.DocCollector) IOException(java.io.IOException) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Collector(org.apache.lucene.search.Collector) ProfileResult(com.yelp.nrtsearch.server.grpc.ProfileResult) Collectors(java.util.stream.Collectors) LargeNumHitsCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.LargeNumHitsCollector) ScriptService(com.yelp.nrtsearch.server.luceneserver.script.ScriptService) SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) List(java.util.List) RescorerCreator(com.yelp.nrtsearch.server.luceneserver.rescore.RescorerCreator) SortFieldCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.SortFieldCollector) RelevanceCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.RelevanceCollector) Collections(java.util.Collections) IndexSearcher(org.apache.lucene.search.IndexSearcher) SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) CollectorResult(com.yelp.nrtsearch.server.grpc.CollectorResult) AdditionalCollectorManager(com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager) LargeNumHitsCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.LargeNumHitsCollector) DocCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.DocCollector) Collector(org.apache.lucene.search.Collector) LargeNumHitsCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.LargeNumHitsCollector) SortFieldCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.SortFieldCollector) RelevanceCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.RelevanceCollector) RelevanceCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.RelevanceCollector) SortFieldCollector(com.yelp.nrtsearch.server.luceneserver.search.collectors.SortFieldCollector)

Aggregations

CollectorResult (com.yelp.nrtsearch.server.grpc.CollectorResult)2 AdditionalCollectorManager (com.yelp.nrtsearch.server.luceneserver.search.collectors.AdditionalCollectorManager)2 DocCollector (com.yelp.nrtsearch.server.luceneserver.search.collectors.DocCollector)2 ArrayList (java.util.ArrayList)2 Collector (org.apache.lucene.search.Collector)2 PluginRescorer (com.yelp.nrtsearch.server.grpc.PluginRescorer)1 ProfileResult (com.yelp.nrtsearch.server.grpc.ProfileResult)1 QueryRescorer (com.yelp.nrtsearch.server.grpc.QueryRescorer)1 SearchRequest (com.yelp.nrtsearch.server.grpc.SearchRequest)1 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)1 VirtualField (com.yelp.nrtsearch.server.grpc.VirtualField)1 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)1 QueryNodeMapper (com.yelp.nrtsearch.server.luceneserver.QueryNodeMapper)1 ShardState (com.yelp.nrtsearch.server.luceneserver.ShardState)1 DefaultSharedDocContext (com.yelp.nrtsearch.server.luceneserver.doc.DefaultSharedDocContext)1 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)1 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)1 VirtualFieldDef (com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef)1 QueryRescore (com.yelp.nrtsearch.server.luceneserver.rescore.QueryRescore)1 RescoreOperation (com.yelp.nrtsearch.server.luceneserver.rescore.RescoreOperation)1