Search in sources :

Example 1 with FilterPostingsEnum

use of org.apache.lucene.index.FilterLeafReader.FilterPostingsEnum in project elasticsearch by elastic.

the class IndexFieldTerm method getPostings.

private PostingsEnum getPostings(int luceneFlags, LeafReader reader) throws IOException {
    assert identifier.field() != null;
    assert identifier.bytes() != null;
    final Fields fields = reader.fields();
    PostingsEnum newPostings = null;
    if (fields != null) {
        final Terms terms = fields.terms(identifier.field());
        if (terms != null) {
            TermsEnum termsEnum = terms.iterator();
            if (termsEnum.seekExact(identifier.bytes())) {
                newPostings = termsEnum.postings(postings, luceneFlags);
                final Bits liveDocs = reader.getLiveDocs();
                if (liveDocs != null) {
                    newPostings = new FilterPostingsEnum(newPostings) {

                        private int doNext(int d) throws IOException {
                            for (; d != NO_MORE_DOCS; d = super.nextDoc()) {
                                if (liveDocs.get(d)) {
                                    return d;
                                }
                            }
                            return NO_MORE_DOCS;
                        }

                        @Override
                        public int nextDoc() throws IOException {
                            return doNext(super.nextDoc());
                        }

                        @Override
                        public int advance(int target) throws IOException {
                            return doNext(super.advance(target));
                        }
                    };
                }
            }
        }
    }
    return newPostings;
}
Also used : Fields(org.apache.lucene.index.Fields) FilterPostingsEnum(org.apache.lucene.index.FilterLeafReader.FilterPostingsEnum) Terms(org.apache.lucene.index.Terms) Bits(org.apache.lucene.util.Bits) IOException(java.io.IOException) PostingsEnum(org.apache.lucene.index.PostingsEnum) FilterPostingsEnum(org.apache.lucene.index.FilterLeafReader.FilterPostingsEnum) TermsEnum(org.apache.lucene.index.TermsEnum)

Aggregations

IOException (java.io.IOException)1 Fields (org.apache.lucene.index.Fields)1 FilterPostingsEnum (org.apache.lucene.index.FilterLeafReader.FilterPostingsEnum)1 PostingsEnum (org.apache.lucene.index.PostingsEnum)1 Terms (org.apache.lucene.index.Terms)1 TermsEnum (org.apache.lucene.index.TermsEnum)1 Bits (org.apache.lucene.util.Bits)1