示例#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);
        }
示例#2
0
        /// <summary>
        /// tests reuse with Pulsing1(Pulsing2(Standard)) </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testNestedPulsing() throws Exception
        public virtual void testNestedPulsing()
        {
            // we always run this test with pulsing codec.
            Codec cp = TestUtil.alwaysPostingsFormat(new NestedPulsingPostingsFormat());
            BaseDirectoryWrapper dir = newDirectory();
            RandomIndexWriter    iw  = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));
            Document             doc = new Document();

            doc.add(new TextField("foo", "a b b c c c d e f g g g h i i j j k l l m m m", Field.Store.NO));
            // note: the reuse is imperfect, here we would have 4 enums (lost reuse when we get an enum for 'm')
            // this is because we only track the 'last' enum we reused (not all).
            // but this seems 'good enough' for now.
            iw.addDocument(doc);
            DirectoryReader ir = iw.Reader;

            iw.close();

            AtomicReader segment = getOnlySegmentReader(ir);
            DocsEnum     reuse   = null;
            IDictionary <DocsEnum, bool?> allEnums = new IdentityHashMap <DocsEnum, bool?>();
            TermsEnum te = segment.terms("foo").iterator(null);

            while (te.next() != null)
            {
                reuse           = te.docs(null, reuse, DocsEnum.FLAG_NONE);
                allEnums[reuse] = true;
            }

            assertEquals(4, allEnums.Count);

            allEnums.Clear();
            DocsAndPositionsEnum posReuse = null;

            te = segment.terms("foo").iterator(null);
            while (te.next() != null)
            {
                posReuse           = te.docsAndPositions(null, posReuse);
                allEnums[posReuse] = true;
            }

            assertEquals(4, allEnums.Count);

            ir.close();
            dir.close();
        }
示例#3
0
        // TODO: this is a basic test. this thing is complicated, add more
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testSophisticatedReuse() throws Exception
        public virtual void testSophisticatedReuse()
        {
            // we always run this test with pulsing codec.
            Codec             cp  = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(1));
            Directory         dir = newDirectory();
            RandomIndexWriter iw  = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));
            Document          doc = new Document();

            doc.add(new TextField("foo", "a b b c c c d e f g g h i i j j k", Field.Store.NO));
            iw.addDocument(doc);
            DirectoryReader ir = iw.Reader;

            iw.close();

            AtomicReader segment = getOnlySegmentReader(ir);
            DocsEnum     reuse   = null;
            IDictionary <DocsEnum, bool?> allEnums = new IdentityHashMap <DocsEnum, bool?>();
            TermsEnum te = segment.terms("foo").iterator(null);

            while (te.next() != null)
            {
                reuse           = te.docs(null, reuse, DocsEnum.FLAG_NONE);
                allEnums[reuse] = true;
            }

            assertEquals(2, allEnums.Count);

            allEnums.Clear();
            DocsAndPositionsEnum posReuse = null;

            te = segment.terms("foo").iterator(null);
            while (te.next() != null)
            {
                posReuse           = te.docsAndPositions(null, posReuse);
                allEnums[posReuse] = true;
            }

            assertEquals(2, allEnums.Count);

            ir.close();
            dir.close();
        }