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
Exemplo n.º 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();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 public void Dispose()
 {
     _writer.Flush(true, true, true);
     _writer.Commit();
     _writer.ExpungeDeletes(true);
     try
     {
         if (Disposing != null)
         {
             Disposing(this, EventArgs.Empty);
         }
     }
     finally
     {
         _writer.Close();
         _resetEvent.Set();
     }
 }
Exemplo n.º 3
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, true);
     Assert.AreEqual(1, r.NumDocs());
     Assert.IsFalse(r.HasDeletions);
     r.Close();
     dir.Close();
 }
Exemplo n.º 4
0
		public virtual void  TestExpungeDeletes3()
		{
			Directory dir = new MockRAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			writer.SetMaxBufferedDocs(2);
			writer.SetMergeFactor(50);
			writer.SetRAMBufferSizeMB(IndexWriter.DISABLE_AUTO_FLUSH);
			
			Document document = new Document();
			
			document = new Document();
			Field storedField = new Field("stored", "stored", Field.Store.YES, Field.Index.NO);
			document.Add(storedField);
			Field termVectorField = new Field("termVector", "termVector", Field.Store.NO, Field.Index.NOT_ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
			document.Add(termVectorField);
			for (int i = 0; i < 98; i++)
				writer.AddDocument(document);
			writer.Close();
			
			IndexReader ir = IndexReader.Open(dir);
			Assert.AreEqual(98, ir.MaxDoc());
			Assert.AreEqual(98, ir.NumDocs());
			for (int i = 0; i < 98; i += 2)
				ir.DeleteDocument(i);
			Assert.AreEqual(49, ir.NumDocs());
			ir.Close();
			
			writer = new IndexWriter(dir, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
			// Force many merges to happen
			writer.SetMergeFactor(3);
			writer.ExpungeDeletes(false);
			writer.Close();
			ir = IndexReader.Open(dir);
			Assert.AreEqual(49, ir.MaxDoc());
			Assert.AreEqual(49, ir.NumDocs());
			ir.Close();
			dir.Close();
		}