public virtual void TestCommitOnClose() { Directory dir = NewDirectory(); IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))); for (int i = 0; i < 14; i++) { AddDoc(writer); } writer.Dispose(); Term searchTerm = new Term("content", "aaa"); DirectoryReader reader = DirectoryReader.Open(dir); IndexSearcher searcher = NewSearcher(reader); ScoreDoc[] hits = searcher.Search(new TermQuery(searchTerm), null, 1000).ScoreDocs; Assert.AreEqual(14, hits.Length, "first number of hits"); reader.Dispose(); reader = DirectoryReader.Open(dir); writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))); for (int i = 0; i < 3; i++) { for (int j = 0; j < 11; j++) { AddDoc(writer); } IndexReader r = DirectoryReader.Open(dir); searcher = NewSearcher(r); hits = searcher.Search(new TermQuery(searchTerm), null, 1000).ScoreDocs; Assert.AreEqual(14, hits.Length, "reader incorrectly sees changes from writer"); r.Dispose(); Assert.IsTrue(reader.IsCurrent(), "reader should have still been current"); } // Now, close the writer: writer.Dispose(); Assert.IsFalse(reader.IsCurrent(), "reader should not be current now"); IndexReader ir = DirectoryReader.Open(dir); searcher = NewSearcher(ir); hits = searcher.Search(new TermQuery(searchTerm), null, 1000).ScoreDocs; Assert.AreEqual(47, hits.Length, "reader did not see changes after writer was closed"); ir.Dispose(); reader.Dispose(); dir.Dispose(); }
public virtual void TestDeleteAllIsCurrent() { // get reader DirectoryReader reader = Writer.GetReader(); // assert index has a document and reader is up2date Assert.AreEqual(1, Writer.NumDocs, "One document should be in the index"); Assert.IsTrue(reader.IsCurrent(), "Document added, reader should be stale "); // remove all documents Writer.DeleteAll(); Writer.Commit(); // assert document has been deleted (index changed), reader is stale Assert.AreEqual(0, Writer.NumDocs, "Document should be removed"); Assert.IsFalse(reader.IsCurrent(), "Reader should be stale"); reader.Dispose(); }
public virtual void TestDeleteByTermIsCurrent() { // get reader DirectoryReader reader = writer.GetReader(); // assert index has a document and reader is up2date Assert.AreEqual(1, writer.NumDocs, "One document should be in the index"); Assert.IsTrue(reader.IsCurrent(), "One document added, reader should be current"); // remove document Term idTerm = new Term("UUID", "1"); writer.DeleteDocuments(idTerm); writer.Commit(); // assert document has been deleted (index changed), reader is stale Assert.AreEqual(0, writer.NumDocs, "Document should be removed"); Assert.IsFalse(reader.IsCurrent(), "Reader should be stale"); reader.Dispose(); }
public override bool IsCurrent() { return(m_input.IsCurrent()); }