Lucene indexing and searching at the same time

六月ゝ 毕业季﹏ 提交于 2020-01-01 05:29:22

问题


I want to search with Lucene on an index. The index is changed frequently. So I need to do something to search and index at the same time. It's a web application on Tomcat. And I want to use RAMDeirectory to increase the searching speed. I don't know how to do it!


回答1:


NRTManager in the misc Lucene package provides the ability to search and index at the same time.

TrackingIndexWriter writer; // your writer
SearcherFactory factory = new SearcherFactory();
NRTManager mgr = new NRTManager(writer, factory);

Check NRTManager methods for more info.




回答2:


You can search and index at the same time using the same index. Look at Lucene's near real time search.

Some example code from the wiki,

IndexWriter writer; // create an IndexWriter here
Document doc = null; // create a document here
writer.addDocument(doc); // update a document
IndexReader reader = writer.getReader(); // get a reader with the new doc
Document addedDoc = reader.document(0);



回答3:


You have to do that either doing a

  1. Batch/overnight operations rebuilding the indexes.
  2. Do that asynch way....

Depends on the requirement, what latency you need.



来源:https://stackoverflow.com/questions/9256226/lucene-indexing-and-searching-at-the-same-time

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