lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Liu <javaca...@gmail.com>
Subject Re: Using IndexReader in the web environment
Date Thu, 06 May 2010 02:53:12 GMT
You may look this:
private static IndexSearcher indexSearcher = null;

 public synchronized IndexSearcher newIndexSearcher() {
  try {

   if (null == indexSearcher) {
    Directory directory = FSDirectory.open(new
File(Config.DB_DIR+"/rssindex"));
    indexSearcher = new IndexSearcher(IndexReader.open(directory, true));
   } else {
    IndexReader indexReader = indexSearcher.getIndexReader();
    IndexReader newIndexReader = indexReader.reopen();//reopen old
indexReader
    if (newIndexReader!=indexReader) {
     indexReader.close();
     indexSearcher.close();


     indexSearcher = new IndexSearcher(newIndexReader);
    }
   }
   return indexSearcher;
  } catch (CorruptIndexException e) {
   log.error(e.getMessage(),e);
   return null;
  } catch (IOException e) {
   log.error(e.getMessage(),e);
   return null;
  }
 }



-- 
冲浪板

my blog:http://chonglangban.appspot.com/
my site:http://kejiblog.appspot.com/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message