Lucene: reopen index index after index

when my search server starts working, it will load the entire index at once for all queries. However, it still uses the old index, even if I rebuild the index. Therefore, I think I should tell the crawler indexReader to open the index again after restoring the index server, but how to implement it? Maybe use the manufacturer-consumer pattern? Although I can use indexReader.isCurrent () to check if the index has changed, but I have to constantly check this for a search or for some period. Is there a more efficient and real-time way?

+6
source share
2 answers

A convenient way to do what you are describing is to use the Lucene SearcherManager helper class. If you are interested in almost real-time searches, you might also be interested in NRTManager .

Mike McCandless has a very good blog article about these two classes.

+6
source

This is by no means an easy task. I had to write quite a lot of code to achieve it (unfortunately, it is in Clojure, so Java code samples are not at hand). The basic principle is to have a thread-safe link to your IndexSearcher, available for both index reading code and index building code. The index builder begins to create a new index in the background; this does not interfere with existing indexes. Upon completion, it enters the synchronized block, closes IndexReader and IndexSearcher, opens a new IndexReader and updates the global IndexSearcher link to the IndexSearcher created from it. All read code must be synchronized with the same lock as the one associated with the specified synchronized block. A better alternative is to use a ReentrantReadWriteLock instead of a synchronized block. This will avoid excessive competition between many read streams.

After initialization during normal operation, you can use the NRTManager to simultaneously read the index and create incremental updates.

0
source

Source: https://habr.com/ru/post/911728/


All Articles