开发者

locking a lucene folder

I am writing a wrapper around Zend's lucene implementation and wanted to add a function rebuildIndex() which reads all relevant fields from 开发者_如何转开发the database and re-creates the index file in a temporary folder. When the operation is finished, I want to replace the original folder with the new one. How can I lock the original lucene folder while replacing its contents? I haven't found anything in Zend's API docs, but I had read somewhere that locking works with files in lucene. Which folders/files do I need?


Lucene use locking internally to maintain index consistency, so you can not use it in your code. I'd suggest using the following strategy:

  1. Create directory 'indexes' which contains directories for 2 different versions of index, e.g. 'index1' and 'index2' and a symlink 'current' to the index that should be used for searches.
  2. When updating index you drop files in inactive index directory, re-create the index and when it's done set 'current' to the newly indexed directory
  3. Wait 1 minute for search queries to the old index files to complete and drop files from the old directory.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜