将lucene版本中的IndexReader.lastModified(目录d)替换为4以上

时间:2016-05-06 12:26:15

标签: lucene

由于在lucene中不推荐使用IndexReader.lastModified(目录d)方法4.请问您应该使用什么代替此代码。

1 个答案:

答案 0 :(得分:1)

Lucene API中不再提供此类方法。 recommended approach如果您需要此信息,则应通过提交数据使其可用。

因此,当您提交索引时,请设置提交数据,如下所示:

Map<String, String> userData = new HashMap<String, String>();
userData.put("lastModified", String.valueOf(new Date().getTime()));
indexWriter.setCommitData(userData);
indexWriter.commit();

然后,当您需要阅读上次提交时间时,可以从DirectoryReader获取,如下所示:

Map<String, String> userData = directoryReader.getIndexCommit().getUserData();
Date lastCommitDate = new Date(Long.parseLong(userData.get("lastModified")));