Search in sources :

Example 1 with CollectorManager

use of org.apache.lucene.search.CollectorManager in project lucene-solr by apache.

the class DrillSideways method search.

/**
   * Search, sorting by {@link Sort}, and computing
   * drill down and sideways counts.
   */
public DrillSidewaysResult search(DrillDownQuery query, Query filter, FieldDoc after, int topN, Sort sort, boolean doDocScores, boolean doMaxScore) throws IOException {
    if (filter != null) {
        query = new DrillDownQuery(config, filter, query);
    }
    if (sort != null) {
        int limit = searcher.getIndexReader().maxDoc();
        if (limit == 0) {
            // the collector does not alow numHits = 0
            limit = 1;
        }
        final int fTopN = Math.min(topN, limit);
        if (executor != null) {
            // We have an executor, let use the multi-threaded version
            final CollectorManager<TopFieldCollector, TopFieldDocs> collectorManager = new CollectorManager<TopFieldCollector, TopFieldDocs>() {

                @Override
                public TopFieldCollector newCollector() throws IOException {
                    return TopFieldCollector.create(sort, fTopN, after, true, doDocScores, doMaxScore);
                }

                @Override
                public TopFieldDocs reduce(Collection<TopFieldCollector> collectors) throws IOException {
                    final TopFieldDocs[] topFieldDocs = new TopFieldDocs[collectors.size()];
                    int pos = 0;
                    for (TopFieldCollector collector : collectors) topFieldDocs[pos++] = collector.topDocs();
                    return TopDocs.merge(sort, topN, topFieldDocs);
                }
            };
            ConcurrentDrillSidewaysResult<TopFieldDocs> r = search(query, collectorManager);
            return new DrillSidewaysResult(r.facets, r.collectorResult);
        } else {
            final TopFieldCollector hitCollector = TopFieldCollector.create(sort, fTopN, after, true, doDocScores, doMaxScore);
            DrillSidewaysResult r = search(query, hitCollector);
            return new DrillSidewaysResult(r.facets, hitCollector.topDocs());
        }
    } else {
        return search(after, query, topN);
    }
}
Also used : Collection(java.util.Collection) TopFieldDocs(org.apache.lucene.search.TopFieldDocs) MultiCollectorManager(org.apache.lucene.search.MultiCollectorManager) CollectorManager(org.apache.lucene.search.CollectorManager) TopFieldCollector(org.apache.lucene.search.TopFieldCollector)

Example 2 with CollectorManager

use of org.apache.lucene.search.CollectorManager in project lucene-solr by apache.

the class DrillSideways method search.

/**
   * Search, sorting by score, and computing
   * drill down and sideways counts.
   */
public DrillSidewaysResult search(ScoreDoc after, DrillDownQuery query, int topN) throws IOException {
    int limit = searcher.getIndexReader().maxDoc();
    if (limit == 0) {
        // the collector does not alow numHits = 0
        limit = 1;
    }
    final int fTopN = Math.min(topN, limit);
    if (executor != null) {
        // We have an executor, let use the multi-threaded version
        final CollectorManager<TopScoreDocCollector, TopDocs> collectorManager = new CollectorManager<TopScoreDocCollector, TopDocs>() {

            @Override
            public TopScoreDocCollector newCollector() throws IOException {
                return TopScoreDocCollector.create(fTopN, after);
            }

            @Override
            public TopDocs reduce(Collection<TopScoreDocCollector> collectors) throws IOException {
                final TopDocs[] topDocs = new TopDocs[collectors.size()];
                int pos = 0;
                for (TopScoreDocCollector collector : collectors) topDocs[pos++] = collector.topDocs();
                return TopDocs.merge(topN, topDocs);
            }
        };
        ConcurrentDrillSidewaysResult<TopDocs> r = search(query, collectorManager);
        return new DrillSidewaysResult(r.facets, r.collectorResult);
    } else {
        TopScoreDocCollector hitCollector = TopScoreDocCollector.create(topN, after);
        DrillSidewaysResult r = search(query, hitCollector);
        return new DrillSidewaysResult(r.facets, hitCollector.topDocs());
    }
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) Collection(java.util.Collection) MultiCollectorManager(org.apache.lucene.search.MultiCollectorManager) CollectorManager(org.apache.lucene.search.CollectorManager)

Aggregations

Collection (java.util.Collection)2 CollectorManager (org.apache.lucene.search.CollectorManager)2 MultiCollectorManager (org.apache.lucene.search.MultiCollectorManager)2 TopDocs (org.apache.lucene.search.TopDocs)1 TopFieldCollector (org.apache.lucene.search.TopFieldCollector)1 TopFieldDocs (org.apache.lucene.search.TopFieldDocs)1 TopScoreDocCollector (org.apache.lucene.search.TopScoreDocCollector)1