Example #1
0
        private static RAMDirectory MakeEmptyIndex(int numDeletedDocs)
        {
            RAMDirectory d = new RAMDirectory();
            IndexWriter  w = new IndexWriter(d, new WhitespaceAnalyzer(), true, MaxFieldLength.LIMITED);

            for (int i = 0; i < numDeletedDocs; i++)
            {
                w.AddDocument(new Document());
            }
            w.Commit();
            w.DeleteDocuments(new MatchAllDocsQuery());
            w.Commit();

            if (0 < numDeletedDocs)
            {
                Assert.IsTrue(w.HasDeletions(), "writer has no deletions");
            }

            Assert.AreEqual(numDeletedDocs, w.MaxDoc(), "writer is missing some deleted docs");
            Assert.AreEqual(0, w.NumDocs(), "writer has non-deleted docs");
            w.Close();
            IndexReader r = IndexReader.Open(d);

            Assert.AreEqual(numDeletedDocs, r.NumDeletedDocs(), "reader has wrong number of deleted docs");
            r.Close();
            return(d);
        }