标签:try pen index 删除索引 nal style conf delete cto
1 /** 2 * 测试删除索引 3 */ 4 @Test 5 public void testDelete(){ 6 IndexWriter writer = null; 7 8 try { 9 //1、创建Directory 10 Directory directory = FSDirectory.open(new File("E:\\lucene\\index2")); 11 12 //2、创建Writer 13 IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, new StandardAnalyzer(Version.LUCENE_35)); 14 writer = new IndexWriter(directory,config); 15 16 //删除文件的索引 17 //删除并不是真的删除,删除的索引信息会被存储到.del(相当于windows的回收站)文件 18 writer.deleteDocuments(new Term("id","2")); 19 } catch (IOException e) { 20 // TODO Auto-generated catch block 21 e.printStackTrace(); 22 } 23 finally{ 24 if(writer != null){ 25 try { 26 writer.close(); 27 } catch (CorruptIndexException e) { 28 // TODO Auto-generated catch block 29 e.printStackTrace(); 30 } catch (IOException e) { 31 // TODO Auto-generated catch block 32 e.printStackTrace(); 33 } 34 } 35 } 36 }
未完待续。。。
标签:try pen index 删除索引 nal style conf delete cto
原文地址:https://www.cnblogs.com/zhzcode/p/9800825.html