Lucene.Net.Index.IndexWriter.ExpungeDeletes C# (CSharp) Method

ExpungeDeletes() public method

Expunges all deletes from the index. When an index has many document deletions (or updates to existing documents), it's best to either call optimize or expungeDeletes to remove all unused data in the index associated with the deleted documents. To see how many deletions you have pending in your index, call IndexReader.NumDeletedDocs This saves disk space and memory usage while searching. expungeDeletes should be somewhat faster than optimize since it does not insist on reducing the index to a single segment (though, this depends on the MergePolicy; see MergePolicy.FindMergesToExpungeDeletes.). Note that this call does not first commit any buffered documents, so you must do so yourself if necessary. See also ExpungeDeletes(bool)

NOTE: if this method hits an OutOfMemoryError you should immediately close the writer. See above for details.

public ExpungeDeletes ( ) : void
return void
		public virtual void  ExpungeDeletes()
		{
			ExpungeDeletes(true);
		}
		

Same methods

IndexWriter::ExpungeDeletes ( bool doWait ) : void

Usage Example

Beispiel #1
0
        public virtual void  TestExpungeDeletes()
        {
            Directory   dir = new MockRAMDirectory();
            IndexWriter w   = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
            Document    doc = new Document();

            doc.Add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
            Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);

            doc.Add(id);
            id.SetValue("0");
            w.AddDocument(doc);
            id.SetValue("1");
            w.AddDocument(doc);
            w.DeleteDocuments(new Term("id", "0"));

            IndexReader r = w.GetReader();

            w.ExpungeDeletes();
            w.Close();
            r.Close();
            r = IndexReader.Open(dir);
            Assert.AreEqual(1, r.NumDocs());
            Assert.IsFalse(r.HasDeletions());
            r.Close();
            dir.Close();
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::ExpungeDeletes
IndexWriter