本文整理汇总了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;
}
}
}
}
示例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();
}
示例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();
}
示例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();
}