Example usage for org.apache.lucene.util DocIdSetBuilder DocIdSetBuilder

List of usage examples for org.apache.lucene.util DocIdSetBuilder DocIdSetBuilder

Introduction

In this page you can find the example usage for org.apache.lucene.util DocIdSetBuilder DocIdSetBuilder.

Prototype

public DocIdSetBuilder(int maxDoc, Terms terms) throws IOException 

Source Link

Document

Create a DocIdSetBuilder instance that is optimized for accumulating docs that match the given Terms .

Usage

From source file:org.elasticsearch.search.aggregations.bucket.composite.TermsSortedDocsProducer.java

License:Apache License

@Override
DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context,
        boolean fillDocIdSet) throws IOException {
    final Terms terms = context.reader().terms(field);
    if (terms == null) {
        // no value for the field
        return DocIdSet.EMPTY;
    }//from  w w w  .j  a  v a 2 s  .  c om
    BytesRef lowerValue = (BytesRef) queue.getLowerValueLeadSource();
    BytesRef upperValue = (BytesRef) queue.getUpperValueLeadSource();
    final TermsEnum te = terms.iterator();
    if (lowerValue != null) {
        if (te.seekCeil(lowerValue) == TermsEnum.SeekStatus.END) {
            return DocIdSet.EMPTY;
        }
    } else {
        if (te.next() == null) {
            return DocIdSet.EMPTY;
        }
    }
    DocIdSetBuilder builder = fillDocIdSet ? new DocIdSetBuilder(context.reader().maxDoc(), terms) : null;
    PostingsEnum reuse = null;
    boolean first = true;
    do {
        if (upperValue != null && upperValue.compareTo(te.term()) < 0) {
            break;
        }
        reuse = te.postings(reuse, PostingsEnum.NONE);
        if (processBucket(queue, context, reuse, te.term(), builder) && !first) {
            // this bucket does not have any competitive composite buckets,
            // we can early terminate the collection because the remaining buckets are guaranteed
            // to be greater than this bucket.
            break;
        }
        first = false;
    } while (te.next() != null);
    return fillDocIdSet ? builder.build() : DocIdSet.EMPTY;
}