Example #1
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();
        }
Example #2
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();
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test10kPulsed() throws Exception
        public virtual void test10kPulsed()
        {
            // we always run this test with pulsing codec.
            Codec cp = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(1));

            File f = createTempDir("10kpulsed");
            BaseDirectoryWrapper dir = newFSDirectory(f);

            dir.CheckIndexOnClose = false;     // we do this ourselves explicitly
            RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));

            Document  document = new Document();
            FieldType ft       = new FieldType(TextField.TYPE_STORED);

            switch (TestUtil.Next(random(), 0, 2))
            {
            case 0:
                ft.IndexOptions = IndexOptions.DOCS_ONLY;
                break;

            case 1:
                ft.IndexOptions = IndexOptions.DOCS_AND_FREQS;
                break;

            default:
                ft.IndexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
                break;
            }

            Field field = newField("field", "", ft);

            document.add(field);

            NumberFormat df = new DecimalFormat("00000", new DecimalFormatSymbols(Locale.ROOT));

            for (int i = 0; i < 10050; i++)
            {
                field.StringValue = df.format(i);
                iw.addDocument(document);
            }

            IndexReader ir = iw.Reader;

            iw.close();

            TermsEnum te = MultiFields.getTerms(ir, "field").iterator(null);
            DocsEnum  de = null;

            for (int i = 0; i < 10050; i++)
            {
                string expected = df.format(i);
                assertEquals(expected, te.next().utf8ToString());
                de = TestUtil.docs(random(), te, null, de, DocsEnum.FLAG_NONE);
                assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
                assertEquals(DocIdSetIterator.NO_MORE_DOCS, de.nextDoc());
            }
            ir.close();

            TestUtil.checkIndex(dir);
            dir.close();
        }
        /// <summary>
        /// a variant, that uses pulsing, but uses a high TF to force pass thru to the underlying codec
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test10kNotPulsed() throws Exception
        public virtual void test10kNotPulsed()
        {
            // we always run this test with pulsing codec.
            int   freqCutoff = TestUtil.Next(random(), 1, 10);
            Codec cp         = TestUtil.alwaysPostingsFormat(new Pulsing41PostingsFormat(freqCutoff));

            File f = createTempDir("10knotpulsed");
            BaseDirectoryWrapper dir = newFSDirectory(f);

            dir.CheckIndexOnClose = false;     // we do this ourselves explicitly
            RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(cp));

            Document  document = new Document();
            FieldType ft       = new FieldType(TextField.TYPE_STORED);

            switch (TestUtil.Next(random(), 0, 2))
            {
            case 0:
                ft.IndexOptions = IndexOptions.DOCS_ONLY;
                break;

            case 1:
                ft.IndexOptions = IndexOptions.DOCS_AND_FREQS;
                break;

            default:
                ft.IndexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
                break;
            }

            Field field = newField("field", "", ft);

            document.add(field);

            NumberFormat df = new DecimalFormat("00000", new DecimalFormatSymbols(Locale.ROOT));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int freq = freqCutoff + 1;
            int freq = freqCutoff + 1;

            for (int i = 0; i < 10050; i++)
            {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < freq; j++)
                {
                    sb.Append(df.format(i));
                    sb.Append(' ');     // whitespace
                }
                field.StringValue = sb.ToString();
                iw.addDocument(document);
            }

            IndexReader ir = iw.Reader;

            iw.close();

            TermsEnum te = MultiFields.getTerms(ir, "field").iterator(null);
            DocsEnum  de = null;

            for (int i = 0; i < 10050; i++)
            {
                string expected = df.format(i);
                assertEquals(expected, te.next().utf8ToString());
                de = TestUtil.docs(random(), te, null, de, DocsEnum.FLAG_NONE);
                assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
                assertEquals(DocIdSetIterator.NO_MORE_DOCS, de.nextDoc());
            }
            ir.close();

            TestUtil.checkIndex(dir);
            dir.close();
        }