Search in sources :

Example 11 with LeafCollector

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

the class DocSetUtil method collectSortedDocSet.

public static void collectSortedDocSet(DocSet docs, IndexReader reader, Collector collector) throws IOException {
    // TODO add SortedDocSet sub-interface and take that.
    // TODO collectUnsortedDocSet: iterate segment, then all docSet per segment.
    final List<LeafReaderContext> leaves = reader.leaves();
    final Iterator<LeafReaderContext> ctxIt = leaves.iterator();
    int segBase = 0;
    int segMax;
    int adjustedMax = 0;
    LeafReaderContext ctx = null;
    LeafCollector leafCollector = null;
    for (DocIterator docsIt = docs.iterator(); docsIt.hasNext(); ) {
        final int doc = docsIt.nextDoc();
        if (doc >= adjustedMax) {
            do {
                ctx = ctxIt.next();
                segBase = ctx.docBase;
                segMax = ctx.reader().maxDoc();
                adjustedMax = segBase + segMax;
            } while (doc >= adjustedMax);
            leafCollector = collector.getLeafCollector(ctx);
        }
        if (doc < segBase) {
            throw new IllegalStateException("algorithm expects sorted DocSet but wasn't: " + docs.getClass());
        }
        // per-seg collectors
        leafCollector.collect(doc - segBase);
    }
}
Also used : LeafCollector(org.apache.lucene.search.LeafCollector) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Aggregations

LeafCollector (org.apache.lucene.search.LeafCollector)11 Scorer (org.apache.lucene.search.Scorer)5 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 Document (org.apache.lucene.document.Document)3 StringField (org.apache.lucene.document.StringField)3 Collector (org.apache.lucene.search.Collector)3 FilterLeafCollector (org.apache.lucene.search.FilterLeafCollector)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 TotalHitCountCollector (org.apache.lucene.search.TotalHitCountCollector)3 Directory (org.apache.lucene.store.Directory)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IndexReader (org.apache.lucene.index.IndexReader)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 TopDocs (org.apache.lucene.search.TopDocs)2 Bits (org.apache.lucene.util.Bits)2 CancellableCollector (org.elasticsearch.search.query.CancellableCollector)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1