Can I use the same instance of IndexSearcher in Lucene.Net by multiple threads concurrently?

蓝咒 提交于 2019-12-10 17:04:59

问题


I want to be able to search by multiple clients and index at the same time in Lucene.Net

Is it possible and thread safe?

Can the same instance of IndexSearcher be shared across threads?


回答1:


The index search CAN and SHOULD be shared across threads.

The trick is deciding when to refresh your searcher with a new snapshot of the index.

I wrote an article showing how I coded sharing a searcher across threads while at the same time making sure that the searcher was always using an up-to-date index.

I'm not saying my solution is the best for everybody - I don't think it would be good for a website with a huge number of searches going on - but it's working fine for my low volume application.

Here's the article:

https://web.archive.org/web/20090612224537/https://ifdefined.com/blog/post/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx




回答2:


Yes.Very much.
Even indexing is!




回答3:


You can index and search concurrently, but the changes you make to the index will not be visible to the searcher till you re-create the searcher. Searcher will have the snapshot of the index when you created the searcher object.



来源:https://stackoverflow.com/questions/1146960/can-i-use-the-same-instance-of-indexsearcher-in-lucene-net-by-multiple-threads-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!