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

ExpungeDeletes() public method

Just like ExpungeDeletes(), except you can specify whether the call should block until the operation completes. This is only meaningful with a MergeScheduler that is able to run merges in background threads.

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

public ExpungeDeletes ( bool doWait ) : void
doWait bool
return void
		public virtual void  ExpungeDeletes(bool doWait)
		{
			EnsureOpen();
			
			if (infoStream != null)
				Message("expungeDeletes: index now " + SegString());
			
			MergePolicy.MergeSpecification spec;
			
			lock (this)
			{
				spec = mergePolicy.FindMergesToExpungeDeletes(segmentInfos);
				if (spec != null)
				{
					int numMerges = spec.merges.Count;
					for (int i = 0; i < numMerges; i++)
						RegisterMerge(spec.merges[i]);
				}
			}
			
			mergeScheduler.Merge(this);
			
			if (spec != null && doWait)
			{
				int numMerges = spec.merges.Count;
				lock (this)
				{
					bool running = true;
					while (running)
					{
						
						if (hitOOM)
						{
							throw new System.SystemException("this writer hit an OutOfMemoryError; cannot complete expungeDeletes");
						}
						
						// Check each merge that MergePolicy asked us to
						// do, to see if any of them are still running and
						// if any of them have hit an exception.
						running = false;
						for (int i = 0; i < numMerges; i++)
						{
							MergePolicy.OneMerge merge = spec.merges[i];
							if (pendingMerges.Contains(merge) || runningMerges.Contains(merge))
								running = true;
							System.Exception t = merge.GetException();
							if (t != null)
							{
								System.IO.IOException ioe = new System.IO.IOException("background merge hit exception: " + merge.SegString(directory), t);
								throw ioe;
							}
						}
						
						// If any of our merges are still running, wait:
						if (running)
							DoWait();
					}
				}
			}
			
			// NOTE: in the ConcurrentMergeScheduler case, when
			// doWait is false, we can return immediately while
			// background threads accomplish the optimization
		}
		

Same methods

IndexWriter::ExpungeDeletes ( ) : 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