Exemple #1
0
 public IndexSearcher getSearcher() {
   try {
     if (reader == null) {
       reader = IndexReader.open(directory, false);
     } else {
       IndexReader tr = IndexReader.openIfChanged(reader);
       if (tr != null) {
         reader.close();
         reader = tr;
       }
     }
     return new IndexSearcher(reader);
   } catch (CorruptIndexException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
 protected void reopenSearcher() throws IOException {
   try {
     reopenLock.lock();
     if (updateCount.get() > 0) {
       logger.info("proccessing reopen...");
       IndexReader oldIndexReader = this.indexReader;
       IndexSearcher oldIndexSearcher = this.indexSearcher;
       IndexReader newIndexReader = IndexReader.openIfChanged(oldIndexReader);
       if (newIndexReader != null) {
         IndexSearcher newIndexSearcher = new IndexSearcher(newIndexReader);
         indexSearcher = newIndexSearcher;
         indexReader = newIndexReader;
         CloseUtil.close(oldIndexReader);
         CloseUtil.close(oldIndexSearcher);
       }
       updateCount.set(0);
       logger.info("proccess reopen finish.");
     } else {
       logger.info("no thing to reopen");
     }
   } finally {
     reopenLock.unlock();
   }
 }