2012-09-04 42 views
0

我的问题涉及到下面的代码片段:Lucene的.NET的IndexWriter锁定

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?这并不似乎是正确的答案给我...

回答

2

它看起来像有一个与构造的IndexWriter一个错误,如果你改变你的代码:

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

您将得到异常。

锁定文件用于防止2个IndexWriter在同一个索引上打开,无论它们是否在同一个进程中。你是对的,期望有一个例外。

+0

看来你是对的!所有的构造函数,而不是字符串将不会抛出异常...我不知道这个问题是否在以后的版本中修复。无论如何,非常感谢:) –