问题
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
- Batch/overnight operations rebuilding the indexes.
- 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