简体   繁体   中英

Lucene indexing and searching at the same time

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!

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.

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM