嗨
我的lucene索引经常用新记录进行更新,我在索引中有5,000,000条记录,并且正在使用FieldCache缓存我的一个数字字段。但在更新索引后,需要一段时间才能重新加载FieldCache(即时重新加载缓存原因文档,表示DocID不可靠),那么如何通过向FieldCache仅添加新添加的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 的技术来提高性能,但它仍然加载,我们已经把所有的文件和我认为如果我们找到一种方法只是将新添加的文档添加到阵列中,则无需重新加载它们全部
你的代码的问题是我用内部/外部阅读器描述的。您将外部阅读器(DirectoryReader)传递给FieldCache。它认为这两个读者是不同的,并分别缓存它们。您需要使用最内层的阅读器,即段阅读器来为每个段填充它。这意味着它只会在你打电话给Reopen之后加载更改。我会在几分钟后为此发布一些代码。 – sisve 2011-04-03 06:50:35