示例#1
0
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
        {
            AtomicReader reader = context.AtomicReader;
            FixedBitSet  result = null;    // lazy init if needed - no need to create a big bitset ahead of time
            Fields       fields = reader.Fields;
            BytesRef     spare  = new BytesRef(this.termsBytes);

            if (fields == null)
            {
                return(result);
            }
            Terms     terms     = null;
            TermsEnum termsEnum = null;
            DocsEnum  docs      = null;

            foreach (TermsAndField termsAndField in this.termsAndFields)
            {
                if ((terms = fields.Terms(termsAndField.field)) != null)
                {
                    termsEnum = terms.iterator(termsEnum);     // this won't return null
                    for (int i = termsAndField.start; i < termsAndField.end; i++)
                    {
                        spare.offset = offsets[i];
                        spare.length = offsets[i + 1] - offsets[i];
                        if (termsEnum.seekExact(spare))
                        {
                            docs = termsEnum.docs(acceptDocs, docs, DocsEnum.FLAG_NONE);     // no freq since we don't need them
                            if (result == null)
                            {
                                if (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    result = new FixedBitSet(reader.maxDoc());
                                    // lazy init but don't do it in the hot loop since we could read many docs
                                    result.set(docs.docID());
                                }
                            }
                            while (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                            {
                                result.set(docs.docID());
                            }
                        }
                    }
                }
            }
            return(result);
        }