本文整理汇总了C#中Lucene.Net.Index.IndexWriter.GetMergeScheduler方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.GetMergeScheduler方法的具体用法?C# IndexWriter.GetMergeScheduler怎么用?C# IndexWriter.GetMergeScheduler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.GetMergeScheduler方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Crash
private void Crash(IndexWriter writer)
{
MockRAMDirectory dir = (MockRAMDirectory) writer.GetDirectory();
ConcurrentMergeScheduler cms = (ConcurrentMergeScheduler) writer.GetMergeScheduler();
dir.Crash();
cms.Sync();
dir.ClearCrash();
}
示例2: InitIndex
private IndexWriter InitIndex(MockRAMDirectory dir)
{
dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer());
//writer.setMaxBufferedDocs(2);
writer.SetMaxBufferedDocs(10);
((ConcurrentMergeScheduler) writer.GetMergeScheduler()).SetSuppressExceptions();
Document doc = new Document();
doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("id", "0", Field.Store.YES, Field.Index.ANALYZED));
for (int i = 0; i < 157; i++)
writer.AddDocument(doc);
return writer;
}
示例3: CreateIndexWriter
private static IndexWriter CreateIndexWriter(Directory directory)
{
var indexWriter = new IndexWriter(directory, new StopAnalyzer(Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED);
var mergeScheduler = indexWriter.GetMergeScheduler();
if(mergeScheduler != null)
mergeScheduler.Close();
indexWriter.SetMergeScheduler(new ErrorLoggingConcurrentMergeScheduler());
return indexWriter;
}
示例4: TestOptimizeMaxNumSegments2
public virtual void TestOptimizeMaxNumSegments2()
{
MockRAMDirectory dir = new MockRAMDirectory();
Document doc = new Document();
doc.Add(new Field("content", "aaa", Field.Store.YES, Field.Index.TOKENIZED));
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
LogDocMergePolicy ldmp = new LogDocMergePolicy();
ldmp.SetMinMergeDocs(1);
writer.SetMergePolicy(ldmp);
writer.SetMergeFactor(4);
writer.SetMaxBufferedDocs(2);
for (int iter = 0; iter < 10; iter++)
{
for (int i = 0; i < 19; i++)
writer.AddDocument(doc);
writer.Flush();
SegmentInfos sis = new SegmentInfos();
((ConcurrentMergeScheduler) writer.GetMergeScheduler()).Sync();
sis.Read(dir);
int segCount = sis.Count;
writer.Optimize(7);
sis = new SegmentInfos();
((ConcurrentMergeScheduler) writer.GetMergeScheduler()).Sync();
sis.Read(dir);
int optSegCount = sis.Count;
if (segCount < 7)
Assert.AreEqual(segCount, optSegCount);
else
Assert.AreEqual(7, optSegCount);
}
}
示例5: 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;
}
}
}
}
示例6: TestAddIndexOnDiskFull
//.........这里部分代码省略.........
System.Console.Out.WriteLine("TEST: iter=" + iter);
// Start with 100 bytes more than we are currently using:
long diskFree = diskUsage + 100;
bool autoCommit = iter % 2 == 0;
int method = iter / 2;
bool success = false;
bool done = false;
System.String methodName;
if (0 == method)
{
methodName = "addIndexes(Directory[])";
}
else if (1 == method)
{
methodName = "addIndexes(IndexReader[])";
}
else
{
methodName = "addIndexesNoOptimize(Directory[])";
}
while (!done)
{
// Make a new dir that will enforce disk usage:
MockRAMDirectory dir = new MockRAMDirectory(startDir);
writer2 = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false);
System.IO.IOException err = null;
MergeScheduler ms = writer2.GetMergeScheduler();
for (int x = 0; x < 2; x++)
{
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.
if (0 == x)
((ConcurrentMergeScheduler)ms).SetSuppressExceptions_ForNUnitTest();
else
((ConcurrentMergeScheduler) ms).ClearSuppressExceptions_ForNUnitTest();
// Two loops: first time, limit disk space &
// throw random IOExceptions; second time, no
// disk space limit:
double rate = 0.05;
double diskRatio = ((double) diskFree) / diskUsage;
long thisDiskFree;
System.String testName = null;
if (0 == x)
{
thisDiskFree = diskFree;
if (diskRatio >= 2.0)
{
rate /= 2;
}
if (diskRatio >= 4.0)
{
rate /= 2;
}
示例7: TestAfterCommit
public virtual void TestAfterCommit()
{
Directory dir1 = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
writer.SetInfoStream(infoStream);
// create the index
CreateIndexNoClose(false, "test", writer);
// get a reader to put writer into near real-time mode
IndexReader r1 = writer.GetReader();
_TestUtil.CheckIndex(dir1);
writer.Commit();
_TestUtil.CheckIndex(dir1);
Assert.AreEqual(100, r1.NumDocs());
for (int i = 0; i < 10; i++)
{
writer.AddDocument(CreateDocument(i, "test", 4));
}
((ConcurrentMergeScheduler) writer.GetMergeScheduler()).Sync();
IndexReader r2 = r1.Reopen();
if (r2 != r1)
{
r1.Close();
r1 = r2;
}
Assert.AreEqual(110, r1.NumDocs());
writer.Close();
r1.Close();
dir1.Close();
}
示例8: TestMergeWarmer
public virtual void TestMergeWarmer()
{
Directory dir1 = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
writer.SetInfoStream(infoStream);
// create the index
CreateIndexNoClose(false, "test", writer);
// get a reader to put writer into near real-time mode
IndexReader r1 = writer.GetReader();
// Enroll warmer
MyWarmer warmer = new MyWarmer();
writer.SetMergedSegmentWarmer(warmer);
writer.SetMergeFactor(2);
writer.SetMaxBufferedDocs(2);
for (int i = 0; i < 10; i++)
{
writer.AddDocument(CreateDocument(i, "test", 4));
}
((ConcurrentMergeScheduler) writer.GetMergeScheduler()).Sync();
Assert.IsTrue(warmer.warmCount > 0);
int count = warmer.warmCount;
writer.AddDocument(CreateDocument(17, "test", 4));
writer.Optimize();
Assert.IsTrue(warmer.warmCount > count);
writer.Close();
r1.Close();
dir1.Close();
}
示例9: Run
override public void Run()
{
bool endLoop = false;
RAMDirectory dir = new RAMDirectory();
IndexWriter w = null;
while (!finish)
{
try
{
//IndexWriter.unlock(dir);
w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
((ConcurrentMergeScheduler) w.GetMergeScheduler()).SetSuppressExceptions();
//w.setInfoStream(System.out);
w.SetMaxBufferedDocs(2);
w.SetMergeFactor(2);
Document doc = new Document();
doc.Add(new Field("field", "some text contents", Field.Store.YES, Field.Index.ANALYZED));
for (int i = 0; i < 100; i++)
{
w.AddDocument(doc);
w.Commit();
}
}
catch (System.SystemException re)
{
System.Exception e = re.InnerException;
if (re is System.Threading.ThreadInterruptedException || e is System.Threading.ThreadInterruptedException)
{
// {{Aroush-2.9}} in Java, this is: java.lang.Thread.interrupted()
//{There is no way in .Net to check interrupted state. So comment it out
//// Make sure IW restored interrupted bit
//if ((Instance.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) != System.Threading.ThreadState.Running) // {{Aroush-2.9}} in Java, this is: java.lang.Thread.interrupted()
//{
// System.Console.Out.WriteLine("FAILED; InterruptedException hit but thread.interrupted() was false");
// System.Console.Out.WriteLine(e.StackTrace);
// failed = true;
// break;
//}
}
else
{
System.Console.Out.WriteLine("FAILED; unexpected exception");
if (e != null)
{
System.Console.Out.WriteLine(e.StackTrace);
}
else
{
System.Console.Out.WriteLine(re.StackTrace);
}
failed = true;
break;
}
}
catch (System.Exception t)
{
System.Console.Out.WriteLine("FAILED; unexpected exception");
System.Console.Out.WriteLine(t.StackTrace);
failed = true;
break;
}
finally
{
try
{
// Clear interrupt if pending
lock (this)
{
Interrupt();
if (w != null)
{
w.Close();
}
}
}
catch (System.Exception t)
{
System.Console.Out.WriteLine("FAILED; unexpected exception during close");
System.Console.Out.WriteLine(t.StackTrace);
failed = true;
endLoop = true;
}
}
if (endLoop) break;
}
if (!failed)
{
try
{
_TestUtil.CheckIndex(dir);
}
catch (System.Exception e)
{
failed = true;
System.Console.Out.WriteLine("CheckIndex FAILED: unexpected exception");
System.Console.Out.WriteLine(e.StackTrace);
}
//.........这里部分代码省略.........
示例10: TestOptimizeExceptions
public virtual void TestOptimizeExceptions()
{
RAMDirectory startDir = new MockRAMDirectory();
IndexWriter w = new IndexWriter(startDir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
w.SetMaxBufferedDocs(2);
w.SetMergeFactor(100);
for (int i = 0; i < 27; i++)
AddDoc(w);
w.Close();
for (int i = 0; i < 200; i++)
{
MockRAMDirectory dir = new MockRAMDirectory(startDir);
w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
((ConcurrentMergeScheduler) w.GetMergeScheduler()).SetSuppressExceptions();
dir.SetRandomIOExceptionRate(0.5, 100);
try
{
w.Optimize();
}
catch (System.IO.IOException ioe)
{
if (ioe.InnerException == null)
Assert.Fail("optimize threw IOException without root cause");
}
w.Close();
dir.Close();
}
}
示例11: RunAddIndexesThreads
public RunAddIndexesThreads(int numCopy)
{
NUM_COPY = numCopy;
dir = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
writer.SetMaxBufferedDocs(2);
for (int i = 0; i < NUM_INIT_DOCS; i++)
AddDoc(writer);
writer.Close();
dir2 = new MockRAMDirectory();
writer2 = new IndexWriter(dir2, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
cms = (ConcurrentMergeScheduler) writer2.GetMergeScheduler();
readers = new IndexReader[NUM_COPY];
for (int i = 0; i < NUM_COPY; i++)
readers[i] = IndexReader.Open(dir);
}
示例12: DoWork
public override void DoWork()
{
IndexWriter writer1 = new IndexWriter(dir1, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
writer1.SetMaxBufferedDocs(3);
writer1.SetMergeFactor(2);
((ConcurrentMergeScheduler) writer1.GetMergeScheduler()).SetSuppressExceptions();
IndexWriter writer2 = new IndexWriter(dir2, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
// Intentionally use different params so flush/merge
// happen @ different times
writer2.SetMaxBufferedDocs(2);
writer2.SetMergeFactor(3);
((ConcurrentMergeScheduler) writer2.GetMergeScheduler()).SetSuppressExceptions();
Update(writer1);
Update(writer2);
TestTransactions.doFail = true;
try
{
lock (lock_Renamed)
{
try
{
writer1.PrepareCommit();
}
catch (System.Exception t)
{
writer1.Rollback();
writer2.Rollback();
return ;
}
try
{
writer2.PrepareCommit();
}
catch (System.Exception t)
{
writer1.Rollback();
writer2.Rollback();
return ;
}
writer1.Commit();
writer2.Commit();
}
}
finally
{
TestTransactions.doFail = false;
}
writer1.Close();
writer2.Close();
}