lucene 索引删除

xieqingtao xieqingtao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我创建文件的一个全文索引,以文件的路径作为关键字,如F:\javapath\java.txt,在创建索引和搜索时都可以成功。但是删除文件索引时以文件路径进行删除不能成功,以文件名可以。这是什么原因?
public boolean delIndex(String path) {
boolean flag = false;
try {
Directory directory = FSDirectory.getDirectory(this.dir);
IndexReader reader = IndexReader.open(directory);

Term term = new Term("path", path);
int deleted = reader.deleteDocuments(term);
LOG.info("-----------------" + deleted + "--" + path);
if (deleted > 0)
flag = true;
reader.close();
directory.close();

} catch (Exception e) {
System.out.println(" caught a " + e.getClass()
+ "\n with message: " + e.getMessage());
}

return flag;
}

public static void main(String args[]) {
FileIndex fi = new FileIndex();
String path = "F:\\javapath\\path.txt";
fi.delIndex(path);
}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
xieqingtao
Java EE 67,535 成员 225,843 内容