在超过4的lucene版本中替换IndexReader.lastModified(目录d)



作为IndexReader.lastModified(目录d)方法在lucene 4中已弃用。你能告诉我应该用什么来代替这个代码吗。

Lucene API中不再提供此类方法。建议的方法是,如果您需要这些信息,您应该通过提交数据提供这些信息。

因此,当您提交到索引时,将提交数据设置为:

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")));

最新更新