本文整理汇总了C#中Lucene.Net.Index.IndexWriter.GetDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Index.IndexWriter.GetDirectory方法的具体用法?C# Lucene.Net.Index.IndexWriter.GetDirectory怎么用?C# Lucene.Net.Index.IndexWriter.GetDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了Lucene.Net.Index.IndexWriter.GetDirectory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDisableLocks
public virtual void TestDisableLocks()
{
System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory4");
Assert.IsTrue(!FSDirectory.GetDisableLocks(), "Locks are already disabled");
FSDirectory.SetDisableLocks(true);
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct default LockFactory: got " + writer.GetDirectory().GetLockFactory());
// Should be no error since locking is disabled:
IndexWriter writer2 = null;
try
{
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine(e.StackTrace);
Assert.Fail("Should not have hit an IOException with locking disabled");
}
FSDirectory.SetDisableLocks(false);
writer.Close();
if (writer2 != null)
{
writer2.Close();
}
// Cleanup
_TestUtil.RmDir(indexDirName);
}
示例2: TestFSDirectoryTwoCreates
public virtual void TestFSDirectoryTwoCreates()
{
System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory2");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()) || typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
// Intentionally do not close the first writer here.
// The goal is to "simulate" a crashed writer and
// ensure the second writer, with create=true, is
// able to remove the lock files. This works OK
// with SimpleFSLockFactory as the locking
// implementation. Note, however, that this test
// will not work on WIN32 when we switch to
// NativeFSLockFactory as the default locking for
// FSDirectory because the second IndexWriter cannot
// remove those lock files since they are held open
// by the first writer. This is because leaving the
// first IndexWriter open is not really a good way
// to simulate a crashed writer.
// Create a 2nd IndexWriter. This should not fail:
IndexWriter writer2 = null;
try
{
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine(e.StackTrace);
Assert.Fail("Should not have hit an IOException with two IndexWriters with create=true, on default SimpleFSLockFactory");
}
writer.Close();
if (writer2 != null)
{
try
{
writer2.Close();
// expected
}
catch (LockReleaseFailedException e)
{
Assert.Fail("writer2.close() should not have hit LockReleaseFailedException");
}
}
// Cleanup
_TestUtil.RmDir(indexDirName);
}
示例3: TestLockClassProperty
public virtual void TestLockClassProperty()
{
System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory3");
System.String prpName = "Lucene.Net.Store.FSDirectoryLockFactoryClass";
try
{
// NoLockFactory:
SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NoLockFactory");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
writer.Close();
// SingleInstanceLockFactory:
SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SingleInstanceLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(SingleInstanceLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
writer.Close();
// NativeFSLockFactory:
SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.NativeFSLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
writer.Close();
// SimpleFSLockFactory:
SupportClass.AppSettings.Set(prpName, "Lucene.Net.Store.SimpleFSLockFactory");
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
writer.Close();
}
finally
{
// Put back to the correct default for subsequent tests:
SupportClass.AppSettings.Set("Lucene.Net.Store.FSDirectoryLockFactoryClass", "");
}
// Cleanup
_TestUtil.RmDir(indexDirName);
}
示例4: TestDefaultFSDirectory
public virtual void TestDefaultFSDirectory()
{
System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory1");
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Assert.IsTrue(typeof(SimpleFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()) || typeof(NativeFSLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct LockFactory: got " + writer.GetDirectory().GetLockFactory());
IndexWriter writer2 = null;
// Create a 2nd IndexWriter. This should fail:
try
{
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
Assert.Fail("Should have hit an IOException with two IndexWriters on default SimpleFSLockFactory");
}
catch (System.IO.IOException e)
{
}
writer.Close();
if (writer2 != null)
{
writer2.Close();
}
// Cleanup
_TestUtil.RmDir(indexDirName);
}