예제 #1
0
 /// <summary>
 /// Expert: same as <seealso cref="#wrap(AtomicReader, Sort)"/> but operates directly on a <seealso cref="Sorter.DocMap"/>. </summary>
 internal static AtomicReader wrap(AtomicReader reader, Sorter.DocMap docMap)
 {
     if (docMap == null)
     {
         // the reader is already sorter
         return(reader);
     }
     if (reader.maxDoc() != docMap.size())
     {
         throw new System.ArgumentException("reader.maxDoc() should be equal to docMap.size(), got" + reader.maxDoc() + " != " + docMap.size());
     }
     Debug.Assert(Sorter.isConsistent(docMap));
     return(new SortingAtomicReader(reader, docMap));
 }
예제 #2
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);
        }
예제 #3
0
 /// <summary>
 /// Expert: same as <seealso cref="#wrap(AtomicReader, Sort)"/> but operates directly on a <seealso cref="Sorter.DocMap"/>. </summary>
 internal static AtomicReader wrap(AtomicReader reader, Sorter.DocMap docMap)
 {
     if (docMap == null)
     {
       // the reader is already sorter
       return reader;
     }
     if (reader.maxDoc() != docMap.size())
     {
       throw new System.ArgumentException("reader.maxDoc() should be equal to docMap.size(), got" + reader.maxDoc() + " != " + docMap.size());
     }
     Debug.Assert(Sorter.isConsistent(docMap));
     return new SortingAtomicReader(reader, docMap);
 }