Scenario Description
To improve efficiency, creating a global variable indexreader replaces the efficiency problem caused by creating an indexreader for each query.
At that time, the Index Service and search service deployed at index 8.23 on one side will be updated every day. The index is updated to 8.25, and the query result is still 8.23.
Tips sharing
Let's take a look at the indexsearcher construction method indexsearcher = new indexsearcher (indexreader );
When you pass in an indexreader, you must know that the reader will not be closed in other cases unless the reader is disabled manually.
So even if the index file changes, indexsearcher won't catch it or update it in time.
Therefore, the searcher service and the index service need to maintain the same update frequency. After the index is updated, the searcher reopens an indexreader.
Indexreader. Close (); indexreaded = new indexreader (directory); indexsearcher = new indexsearcher (indexreader );
Tips -- indexsearcher automatic update