当前位置: 首页>>代码示例>>C#>>正文


C# IndexWriter.Abort方法代码示例

本文整理汇总了C#中Lucene.Net.Index.IndexWriter.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.Abort方法的具体用法?C# IndexWriter.Abort怎么用?C# IndexWriter.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Index.IndexWriter的用法示例。


在下文中一共展示了IndexWriter.Abort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAddDocumentOnDiskFull

		public virtual void  TestAddDocumentOnDiskFull()
		{
			
			bool debug = false;
			
			for (int pass = 0; pass < 3; pass++)
			{
				if (debug)
					System.Console.Out.WriteLine("TEST: pass=" + pass);
				bool autoCommit = pass == 0;
				bool doAbort = pass == 2;
				long diskFree = 200;
				while (true)
				{
					if (debug)
						System.Console.Out.WriteLine("TEST: cycle: diskFree=" + diskFree);
					MockRAMDirectory dir = new MockRAMDirectory();
					dir.SetMaxSizeInBytes(diskFree);
					IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true);
					
					MergeScheduler ms = writer.GetMergeScheduler();
					if (ms is ConcurrentMergeScheduler)
					// This test intentionally produces exceptions
					// in the threads that CMS launches; we don't
					// want to pollute test output with these.
						((ConcurrentMergeScheduler)ms).SetSuppressExceptions_ForNUnitTest();
					
					bool hitError = false;
					try
					{
						for (int i = 0; i < 200; i++)
						{
							AddDoc(writer);
						}
					}
					catch (System.IO.IOException e)
					{
						if (debug)
						{
							System.Console.Out.WriteLine("TEST: exception on addDoc");
							System.Console.Out.WriteLine(e.StackTrace);
						}
						hitError = true;
					}
					
					if (hitError)
					{
						if (doAbort)
						{
							writer.Abort();
						}
						else
						{
							try
							{
								writer.Close();
							}
							catch (System.IO.IOException e)
							{
								if (debug)
								{
									System.Console.Out.WriteLine("TEST: exception on close");
									System.Console.Out.WriteLine(e.StackTrace);
								}
								dir.SetMaxSizeInBytes(0);
								writer.Close();
							}
						}
						
						_TestUtil.SyncConcurrentMerges(ms);
						
						AssertNoUnreferencedFiles(dir, "after disk full during addDocument with autoCommit=" + autoCommit);
						
						// Make sure reader can open the index:
						IndexReader.Open(dir).Close();
						
						dir.Close();
						
						// Now try again w/ more space:
						diskFree += 500;
					}
					else
					{
						_TestUtil.SyncConcurrentMerges(writer);
						dir.Close();
						break;
					}
				}
			}
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:90,代码来源:TestIndexWriter.cs

示例2: TestCommitOnCloseAbort

		public virtual void  TestCommitOnCloseAbort()
		{
			Directory dir = new RAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			writer.SetMaxBufferedDocs(10);
			for (int i = 0; i < 14; i++)
			{
				AddDoc(writer);
			}
			writer.Close();
			
			Term searchTerm = new Term("content", "aaa");
			IndexSearcher searcher = new IndexSearcher(dir);
			Hits hits = searcher.Search(new TermQuery(searchTerm));
			Assert.AreEqual(14, hits.Length(), "first number of hits");
			searcher.Close();
			
			writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), false);
			writer.SetMaxBufferedDocs(10);
			for (int j = 0; j < 17; j++)
			{
				AddDoc(writer);
			}
			// Delete all docs:
			writer.DeleteDocuments(searchTerm);
			
			searcher = new IndexSearcher(dir);
			hits = searcher.Search(new TermQuery(searchTerm));
			Assert.AreEqual(14, hits.Length(), "reader incorrectly sees changes from writer with autoCommit disabled");
			searcher.Close();
			
			// Now, close the writer:
			writer.Abort();
			
			AssertNoUnreferencedFiles(dir, "unreferenced files remain after abort()");
			
			searcher = new IndexSearcher(dir);
			hits = searcher.Search(new TermQuery(searchTerm));
			Assert.AreEqual(14, hits.Length(), "saw changes after writer.abort");
			searcher.Close();
			
			// Now make sure we can re-open the index, add docs,
			// and all is good:
			writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), false);
			writer.SetMaxBufferedDocs(10);
			for (int i = 0; i < 12; i++)
			{
				for (int j = 0; j < 17; j++)
				{
					AddDoc(writer);
				}
				searcher = new IndexSearcher(dir);
				hits = searcher.Search(new TermQuery(searchTerm));
				Assert.AreEqual(14, hits.Length(), "reader incorrectly sees changes from writer with autoCommit disabled");
				searcher.Close();
			}
			
			writer.Close();
			searcher = new IndexSearcher(dir);
			hits = searcher.Search(new TermQuery(searchTerm));
			Assert.AreEqual(218, hits.Length(), "didn't see changes after close");
			searcher.Close();
			
			dir.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:65,代码来源:TestIndexWriter.cs

示例3: TestCommitOnCloseOptimize

		public virtual void  TestCommitOnCloseOptimize()
		{
			RAMDirectory dir = new RAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
			writer.SetMaxBufferedDocs(10);
			for (int j = 0; j < 17; j++)
			{
				AddDocWithIndex(writer, j);
			}
			writer.Close();
			
			writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), false);
			writer.Optimize();
			
			// Open a reader before closing (commiting) the writer:
			IndexReader reader = IndexReader.Open(dir);
			
			// Reader should see index as unoptimized at this
			// point:
			Assert.IsFalse(reader.IsOptimized(), "Reader incorrectly sees that the index is optimized");
			reader.Close();
			
			// Abort the writer:
			writer.Abort();
			AssertNoUnreferencedFiles(dir, "aborted writer after optimize");
			
			// Open a reader after aborting writer:
			reader = IndexReader.Open(dir);
			
			// Reader should still see index as unoptimized:
			Assert.IsFalse(reader.IsOptimized(), "Reader incorrectly sees that the index is optimized");
			reader.Close();
			
			writer = new IndexWriter(dir, false, new WhitespaceAnalyzer(), false);
			writer.Optimize();
			writer.Close();
			AssertNoUnreferencedFiles(dir, "aborted writer after optimize");
			
			// Open a reader after aborting writer:
			reader = IndexReader.Open(dir);
			
			// Reader should still see index as unoptimized:
			Assert.IsTrue(reader.IsOptimized(), "Reader incorrectly sees that the index is unoptimized");
			reader.Close();
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:45,代码来源:TestIndexWriter.cs

示例4: TestExceptionsDuringCommit

		public virtual void  TestExceptionsDuringCommit()
		{
			MockRAMDirectory dir = new MockRAMDirectory();
			FailOnlyInCommit failure = new FailOnlyInCommit();
			IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
			Document doc = new Document();
			doc.Add(new Field("field", "a field", Field.Store.YES, Field.Index.ANALYZED));
			w.AddDocument(doc);
			dir.FailOn(failure);
			try
			{
				w.Close();
				Assert.Fail();
			}
			catch (System.IO.IOException ioe)
			{
				Assert.Fail("expected only RuntimeException");
			}
			catch (System.SystemException re)
			{
				// Expected
			}
			Assert.IsTrue(failure.fail1 && failure.fail2);
			w.Abort();
			dir.Close();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:26,代码来源:TestIndexWriter.cs


注:本文中的Lucene.Net.Index.IndexWriter.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。