Lucene near real time search

半城伤御伤魂 提交于 2019-12-06 13:42:21

Try to use a SearcherManager instead of a IndexReader: http://lucene.apache.org/core/6_6_0/core/org/apache/lucene/search/SearcherManager.html

Based on the SearcherManager your able to execute following methods:

// get a IndexSearcher for searching
IndexSearcher searcher = searcherManager.aquire();

// release IndexSearcher after search
searcherManager.release(searcher);

// refresh and add new index records to next search. usually after a commit 
searcherManager.maybeRefresh();

I tried to implement this as well and basically i did this:

  • create an IndexWriter and leave it open
  • create a SearcherManager with the IndexWriter as param.
  • use SearcherManager to search
  • use IndexWriter for indexing operations.
  • commit after indexing

Additionally you can use a separate thread to commit periodically and not on every write because the commit operation may be pretty "expensive".

Example here: http://www.lucenetutorial.com/lucene-nrt-hello-world.html

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