Lucene-打开一个封闭的IndexWriter [英] Lucene - open a closed IndexWriter

查看:58
本文介绍了Lucene-打开一个封闭的IndexWriter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我执行add()将文档添加到索引中,然后关闭().很好!

Heres my issue, I perform add() to add documents to my index and then I close() it. That works great!

现在,我有一个新要求,每次我将某些内容保存到数据库中时,都需要更新索引.我无法再次创建indexWriter,因为它花费了超过4分钟的时间,因此我只需要将文档update()或add()添加到索引中即可.

Now I have a new requirement and every time I save something in my DB I need to update my Index. I can't create again the indexWriter because it takes more than 4 minutes so I just need to update() or add() a document to the index.

要实现它,我没有做index.close(),而是在填充索引后做index.commit()...但是我认为它应该先关闭然后再打开update().

To accomplish it, I'm not doing index.close(), I'm doing index.commit() after I populate my index... but i think it should be close and then open to update().

有什么建议吗?谢谢!

推荐答案

将所有更改提交给索引,然后 关闭所有关联的文件.注意 这可能是一项昂贵的操作,所以, 尝试重新使用一个作家 关闭并打开一个新的容器.

Commits all changes to an index and closes all associated files. Note that this may be a costly operation, so, try to re-use a single writer instead of closing and opening a new one.

我相信closecommit之间的区别在于commit仅刷新数据以使其对读者可见,而close也会优化索引.这使commit大约 5次close快.

I believe that the difference between close and commit is that commit only flushes the data to make it visible to readers whereas close optimises the index too. This makes commit about 5 times faster than close.

如果要连续添加数据,最好先完成commit,然后再完成close.

If you are adding data continuously, it is better to commit and then finally close when you are all done.

这篇关于Lucene-打开一个封闭的IndexWriter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆