更新Lucene索引时出现异常

Ste*_*man 4 c# lucene lucene.net

是Lucene搜索API的新手.我在更新Lucene索引时不断遇到异常...为什么我会收到此错误,我该如何避免呢?

System.IO.IOException: Lock obtain timed out: SimpleFSLock@C:\Indexes\write.lock
   at Lucene.Net.Store.Lock.Obtain(Int64 lockWaitTimeout)
   at Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean create, Boolean closeDir)
   at Lucene.Net.Index.IndexWriter.Init(String path, Analyzer a, Boolean create)
   at Lucene.Net.Index.IndexWriter..ctor(String path, Analyzer a, Boolean create)
Run Code Online (Sandbox Code Playgroud)

谢谢阅读.

Sha*_*ore 11

在写入模式下打开索引时,Lucene会创建锁定文件.当您完全关闭索引时,将删除此锁定文件.在编写索引时,如果程序在不关闭lucene IndexWriter的情况下退出,则下次尝试写入时会出现此异常.如果从索引目录中删除锁定文件,则不会看到此异常.

您可以选择使用FSDirectory.setDisableLocks(false)禁用锁定,但这是不可取的,因为会以静默方式忽略错误.