Hi
我的 lucene 索引经常使用新记录进行更新,我的索引中有 5,000,000 条记录,并且我正在使用 FieldCache 缓存我的数字字段之一。但是更新索引后,需要时间再次重新加载 FieldCache(我重新加载缓存,因为文档说 DocID 不可靠),所以如何通过仅将新添加的 DocID 添加到 FieldCache 来最小化这种开销,因为此功能变成了我的瓶颈应用。
IndexReader reader = IndexReader.Open(diskDir);
int[] dateArr = FieldCache_Fields.DEFAULT.GetInts(reader, "newsdate"); // This line takes 4 seconds to load the array
dateArr = FieldCache_Fields.DEFAULT.GetInts(reader, "newsdate"); // this line takes 0 second as we expected
// HERE we add some document to index and we need to reload the index to reflect changes
reader = reader.Reopen();
dateArr = FieldCache_Fields.DEFAULT.GetInts(reader, "newsdate"); // This takes 4 second again to load the array
我想要一种机制,通过仅将新添加的文档添加到数组中的索引来最小化这个时间,有一种这样的技术http://invertedindex.blogspot.com/2009/04/lucene-dociduid-mapping-and-payload.html提高性能,但它仍然加载我们已有的所有文档,并且我认为如果我们找到一种仅将新添加的文档添加到数组中的方法,则无需重新加载所有文档
FieldCache 使用对索引读取器的弱引用作为其缓存的键。 (通过调用IndexReader.GetCacheKey
尚未废弃。)标准调用IndexReader.Open
with a FSDirectory
将使用一组读者,每个细分市场都有一个读者。
您应该始终将最里面的读取器传递给 FieldCache。查看ReaderUtil
对于一些辅助工具来检索包含在其中的单个读者的文档。文档 ID 不会在段内更改,当将其描述为不可预测/易失性时,它们的意思是它会在两次索引提交之间更改。可能会发生已删除的文档、已合并片段等操作。
提交需要从磁盘中删除该段(合并/优化),这意味着新的读取器不会拥有池化的段读取器,并且一旦所有旧读取器关闭,垃圾收集就会将其删除。
永远,永远,打电话FieldCache.PurgeAllCaches()
。它用于测试,而不是生产用途。
2011-04-03 添加;使用子阅读器的示例代码。
var directory = FSDirectory.Open(new DirectoryInfo("index"));
var reader = IndexReader.Open(directory, readOnly: true);
var documentId = 1337;
// Grab all subreaders.
var subReaders = new List<IndexReader>();
ReaderUtil.GatherSubReaders(subReaders, reader);
// Loop through all subreaders. While subReaderId is higher than the
// maximum document id in the subreader, go to next.
var subReaderId = documentId;
var subReader = subReaders.First(sub => {
if (sub.MaxDoc() < subReaderId) {
subReaderId -= sub.MaxDoc();
return false;
}
return true;
});
var values = FieldCache_Fields.DEFAULT.GetInts(subReader, "newsdate");
var value = values[subReaderId];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)