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) 

Source Link

Document

Create a builder that can contain doc IDs between 0 and maxDoc .

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  w ww .j  a v a2s  .  c  om
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: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  a va  2 s .co  m*/
    while (termsEnum.next() != null) {
        docs = termsEnum.postings(docs, PostingsEnum.NONE);
        builder.add(docs);
    }

    return builder.build();
}