lucene 删除索引

public static void deleteDocument(HttpServletRequest request, String id){

String pa = request.getRealPath("").replace("fangdake", "");

String pathdir =pa+"fasdq"+File.separator+PrePath ;

Analyzer analyzer = new IKAnalyzer();

File path = new File(pathdir);

try {

Directory directory = FSDirectory.open(path);

IndexReader reader = IndexReader.open(directory,false);

// indexWriter.setUseCompoundFile(true);

reader.deleteDocuments(new Term("id",id));

// reader.deleteDocument(10);

reader.flush();   

   reader.close();   

System.out.println("删除索引");

} catch (CorruptIndexException e) {

e.printStackTrace();

} catch (LockObtainFailedException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

你可能感兴趣的:(String,File,Lucene,Path)