public IndexSearcher newIndexSearcher() { try { if(null==isearcher){ isearcher = new IndexSearcher(IndexReader.open("D:/Index")); }else{ IndexReader indexReader=isearcher.getIndexReader();//获取当前的indexReader if(!indexReader.isCurrent()){//判断是否有索引更新 // 如果有索引更新,先关闭当前的indexSearcher closeIndexSearcher(); //利用indexReader.reopen()获取新的indexReader,并作为IndexSearcher的参数创建一个新的indexSearcher isearcher=new IndexSearcher(indexReader.reopen()); } } return isearcher; } catch (CorruptIndexException e) { //e.printStackTrace(); return null; } catch (IOException e) { //e.printStackTrace(); return null; } }