Directory lock error with Lucene.Net usage in an ASP.NET MVC site

后端 未结 6 2173
陌清茗
陌清茗 2021-02-13 21:29

I\'m building an ASP.NET MVC site where I want to use Lucene.Net for search. I\'ve already built a SearchController and all of its methods, but I\'m getting an error at runtime

6条回答
  •  感动是毒
    2021-02-13 21:46

    The reason why this happens is that the writer creates an empty file called write.lock as a cross-process lock. When that file exists, Lucene assumes that someone has a write lock on that directory.

    When you terminate your process incorrectly, the file will not get deleted. So Lucene thinks that someone is still holding on to the lock. That's why you should always have a finally statement which closes the index.

    If you are sure that the file is there in error (i.e. no Lucene processes are running) it is fine to just delete the file. Your index may, however, be in a corrupted state, since the writing was obviously terminated midstream.

提交回复
热议问题