dcsimg
Keeping an IndexSearcher object up to date
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Greet_Truijen
Posted On:   Thursday, July 27, 2006 02:29 AM

Suppose some external program is able to change the index that you are searching. How can you make sure your IndexSearcher object is up to date? At the moment, we've solved this problem in the following way: private IndexSearcher getIndexSearcher() throws IOException { // check if update is necessary if ( _lastModified != getLastModified() ) { // close old searcher _searcher.close(); _searcher = new IndexSearcher( _indexLocation ); _lastModified = getLastModified(); logger.debug( "index searcher [" + _indexLocation + "] was updated" ); } return _searcher;    More>>

Suppose some external program is able to change the index that you are searching.

How can you make sure your IndexSearcher object is up to date?


At the moment, we've solved this problem in the following way:

			
private IndexSearcher getIndexSearcher()
throws IOException {

// check if update is necessary

if ( _lastModified != getLastModified() ) {

// close old searcher

_searcher.close();


_searcher = new IndexSearcher( _indexLocation );

_lastModified = getLastModified();

logger.debug( "index searcher [" + _indexLocation + "] was updated" );

}


return _searcher;

}



Summarized: a new IndexSearcher object is initialized if the index is modified.

Is there a better way to handle this problem? Does the latest version of Lucene support this issue?

   <<Less

Re: Keeping an IndexSearcher object up to date

Posted By:   Otis_Gospodnetic  
Posted On:   Thursday, July 27, 2006 09:25 PM

You have to check the version number. IndexReader has a method for that. If the version is newer, get a new IndexSearcher and throw the old one away.
About | Sitemap | Contact