g334886884
g334886884
2011-10-18 11:15

Lucene某条索引删除问题

已采纳

我想问下
public static void deleteOneIndex(String indexDir, Analyzer analyzer,
String field, String key) {
try {
Directory dir = new SimpleFSDirectory(new File(indexDir));
IndexWriter indexWriter = new IndexWriter(dir, analyzer, false,
IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter.deleteDocuments(new Term(field, key));
indexWriter.optimize();
indexWriter.commit();
System.out.println("是否删除成功=" + indexWriter.hasDeletions());
System.out.println("一共有" + indexWriter.maxDoc() + "索引");
System.out.println("还剩" + indexWriter.numDocs() + "索引");
indexWriter.close();
} catch (IOException e) {
System.out.println(" caught a " + e.getClass()
+ "\n with message: " + e.getMessage());
}
}
这样为什么没有删除掉我想删除的索引
例如:deleteOneIndex("D:\logs\lucenedoc",new StandardAnalyzer(Version.LUCENE_33),"name","张三");
没有分了 希望指点下,不胜感激!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答