Lucene.Net.Index.IndexWriter.PrepareCommit C# (CSharp) Метод

PrepareCommit() приватный Метод

Expert: prepare for commit, specifying commitUserData Map (String -> String). This does the first phase of 2-phase commit. This method does all steps necessary to commit changes since this writer was opened: flushes pending added and deleted docs, syncs the index files, writes most of next segments_N file. After calling this you must call either Commit() to finish the commit, or Rollback() to revert the commit and undo all changes done since the writer was opened.

You can also just call Commit(IDictionary{string,string}) directly without prepareCommit first in which case that method will internally call prepareCommit.

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

private PrepareCommit ( string>.IDictionary commitUserData ) : void
commitUserData string>.IDictionary Opaque Map (String->String) /// that's recorded into the segments file in the index, /// and retrievable by . /// Note that when IndexWriter commits itself, during , the /// commitUserData is unchanged (just carried over from /// the prior commit). If this is null then the previous /// commitUserData is kept. Also, the commitUserData will /// only "stick" if there are actually changes in the /// index to commit. ///
Результат void
        private void PrepareCommit(IDictionary<string, string> commitUserData)
		{
			if (hitOOM)
			{
				throw new System.SystemException("this writer hit an OutOfMemoryError; cannot commit");
			}
			
			if (pendingCommit != null)
				throw new System.SystemException("prepareCommit was already called with no corresponding call to commit");
			
			if (infoStream != null)
				Message("prepareCommit: flush");
			
			Flush(true, true, true);
			
			StartCommit(0, commitUserData);
		}
		

Same methods

IndexWriter::PrepareCommit ( ) : void

Usage Example

Пример #1
0
        public virtual void TestPrepareCommit()
        {
            Directory dir = NewDirectory();

            IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy(5)));

            writer.Commit();

            for (int i = 0; i < 23; i++)
            {
                AddDoc(writer);
            }

            DirectoryReader reader = DirectoryReader.Open(dir);

            Assert.AreEqual(0, reader.NumDocs);

            writer.PrepareCommit();

            IndexReader reader2 = DirectoryReader.Open(dir);

            Assert.AreEqual(0, reader2.NumDocs);

            writer.Commit();

            IndexReader reader3 = DirectoryReader.OpenIfChanged(reader);

            Assert.IsNotNull(reader3);
            Assert.AreEqual(0, reader.NumDocs);
            Assert.AreEqual(0, reader2.NumDocs);
            Assert.AreEqual(23, reader3.NumDocs);
            reader.Dispose();
            reader2.Dispose();

            for (int i = 0; i < 17; i++)
            {
                AddDoc(writer);
            }

            Assert.AreEqual(23, reader3.NumDocs);
            reader3.Dispose();
            reader = DirectoryReader.Open(dir);
            Assert.AreEqual(23, reader.NumDocs);
            reader.Dispose();

            writer.PrepareCommit();

            reader = DirectoryReader.Open(dir);
            Assert.AreEqual(23, reader.NumDocs);
            reader.Dispose();

            writer.Commit();
            reader = DirectoryReader.Open(dir);
            Assert.AreEqual(40, reader.NumDocs);
            reader.Dispose();
            writer.Dispose();
            dir.Dispose();
        }
All Usage Examples Of Lucene.Net.Index.IndexWriter::PrepareCommit
IndexWriter