简体   繁体   English

Lucene .NET IndexWriter锁

[英]Lucene .NET IndexWriter lock

My question related to the next code snippet: 我的问题与下一个代码段有关:

  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...
}

In this test, I opened an IndexWriter without closing it - so even after the test exits, the write.lock file still exists in the index directory, so I expected that the next time I open an instance of IndexWriter to that index, a LockObatinFailedException will be thrown. 在这个测试中,我打开了一个IndexWriter而没有关闭它 - 所以即使在测试退出之后,write.lock文件仍然存在于索引目录中,所以我预计下次我打开一个IndexWriter实例到该索引时,一个LockObatinFailedException将被抛出。 Can someone please explain to me why am I wrong? 有人可以向我解释为什么我错了吗? I mean, does the meaning of the write.lock file is to protect creation of two IndexWriters in the same process only? 我的意思是,write.lock文件的含义是仅保护在同一进程中创建两个IndexWriters吗? that doesnt seems the right answer to me... 这对我来说似乎不是正确的答案......

It looks like there is a bug with that IndexWriter constructor, if you change your code to: 如果您将代码更改为以下内容,则看起来该IndexWriter构造函数存在错误:

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

You will get the Exception. 你会得到例外。

The lock file is used to prevent 2 IndexWriter opened on the same index, whether they are in the same process or not. 锁定文件用于防止在同一索引上打开2个IndexWriter,无论它们是否在同一进程中。 You are right to expect an Exception there. 你在那里期待一个例外是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM