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

DocIdSetBuilder(int maxDoc, int docCount, long valueCount) 

Source Link

Usage

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

License:Apache License

@Override
DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context,
        boolean fillDocIdSet) throws IOException {
    final PointValues values = context.reader().getPointValues(field);
    if (values == null) {
        // no value for the field
        return DocIdSet.EMPTY;
    }//  ww  w .java  2 s .  c o m
    long lowerBucket = Long.MIN_VALUE;
    Comparable<?> lowerValue = queue.getLowerValueLeadSource();
    if (lowerValue != null) {
        if (lowerValue.getClass() != Long.class) {
            throw new IllegalStateException("expected Long, got " + lowerValue.getClass());
        }
        lowerBucket = (Long) lowerValue;
    }

    long upperBucket = Long.MAX_VALUE;
    Comparable<?> upperValue = queue.getUpperValueLeadSource();
    if (upperValue != null) {
        if (upperValue.getClass() != Long.class) {
            throw new IllegalStateException("expected Long, got " + upperValue.getClass());
        }
        upperBucket = (Long) upperValue;
    }
    DocIdSetBuilder builder = fillDocIdSet ? new DocIdSetBuilder(context.reader().maxDoc(), values, field)
            : null;
    Visitor visitor = new Visitor(context, queue, builder, values.getBytesPerDimension(), lowerBucket,
            upperBucket);
    try {
        values.intersect(visitor);
        visitor.flush();
    } catch (CollectionTerminatedException exc) {
    }
    return fillDocIdSet ? builder.build() : DocIdSet.EMPTY;
}