Lucene .NET IndexWriter lock



我的问题与下一个代码片段有关:

  static void Main(string[] args)
{
    Lucene.Net.Store.Directory d = FSDirectory.Open(new DirectoryInfo(/*my index path*/));
    IndexWriter writer = new IndexWriter(d, new WhitespaceAnalyzer());
    //Exiting without closing the indexd writer...
}

在这个测试中,我打开了一个IndexWriter而没有关闭它,所以即使在测试退出后,write.lock文件仍然存在于索引目录中,所以我预计下次打开该索引的IndexWriter实例时,会抛出一个LockObatinFailedException。有人能向我解释一下我为什么错了吗?我的意思是,write.lock文件的意义是仅仅保护在同一过程中创建两个IndexWriters吗?这对我来说似乎不是正确的答案…

如果您将代码更改为:,那么IndexWriter构造函数似乎有一个错误

IndexWriter writer = new IndexWriter("Path to index here", new WhitespaceAnalyzer());

您将获得异常。

锁定文件用于阻止在同一索引上打开2个IndexWriter,无论它们是否在同一进程中。您期望出现异常是正确的。

最新更新