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

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

Introduction

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

Prototype

public DocIdSet build() 

Source Link

Document

Build a DocIdSet from the accumulated doc IDs.

Usage

From source file:org.codelibs.elasticsearch.search.slice.TermsSliceQuery.java

License:Apache License

/**
 * Returns a DocIdSet per segments containing the matching docs for the specified slice.
 *///from ww  w. ja va  2 s . com
private DocIdSet build(LeafReader reader) throws IOException {
    final DocIdSetBuilder builder = new DocIdSetBuilder(reader.maxDoc());
    final Terms terms = reader.terms(getField());
    final TermsEnum te = terms.iterator();
    PostingsEnum docsEnum = null;
    for (BytesRef term = te.next(); term != null; term = te.next()) {
        int hashCode = term.hashCode();
        if (contains(hashCode)) {
            docsEnum = te.postings(docsEnum, PostingsEnum.NONE);
            builder.add(docsEnum);
        }
    }
    return builder.build();
}

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;
    }//from w  ww  .  j  a v  a2  s . co 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;
}

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   ww w .  j a  va  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;
}

From source file:solutions.siren.join.index.query.TermsEnumTermsQuery.java

License:Open Source License

public DocIdSet getDocIdSet(LeafReaderContext context) throws IOException {
    final Terms terms = context.reader().terms(field);
    // make sure the field exists
    if (terms == null)
        return null;

    final BytesRefTermsSet termsSet = this.getTermsSet();
    // make sure there are terms to filter on
    if (termsSet == null || termsSet.isEmpty())
        return null;

    SeekingTermSetTermsEnum termsEnum = new SeekingTermSetTermsEnum(terms.iterator(), termsSet);

    DocIdSetBuilder builder = new DocIdSetBuilder(context.reader().maxDoc());
    PostingsEnum docs = null;//from w w  w .  j av a2 s  .c  o m
    while (termsEnum.next() != null) {
        docs = termsEnum.postings(docs, PostingsEnum.NONE);
        builder.add(docs);
    }

    return builder.build();
}