【问题标题】:Lucene: How to get real-time index information during indexing? (Index size and term count)Lucene:索引过程中如何获取实时索引信息? (索引大小和术语计数)
【发布时间】:2012-12-20 21:47:08
【问题描述】:

我想在索引过程中实时获取Lucene的索引信息。所以我在我的代码中使用了 CheckIndex 类,如下:

CheckIndex.Status indexStatus = checkIndex.checkIndex();
Iterator<CheckIndex.Status.SegmentInfoStatus> iterator = indexStatus.segmentInfos.iterator();
CheckIndex.Status.SegmentInfoStatus temp = null;
while(iterator.hasNext()) {
    temp = iterator.next();
    term_number += temp.termIndexStatus.termCount;
    index_MB_size += temp.sizeMB;
}

起初,索引文件夹是空的。每次 Lucene 完成对文本文件(每个大约 10MB,大约 600MB)的索引时,我都会输出 term_numberindex_MB_size。所以我得到了大约 60 对结果。但是我很伤心地发现60对中的2个变量始终为0。只有当索引段结束时,统计信息才会显示非零结果。

我猜这是因为 CheckIndex 类只有在索引完成后才能正常工作。但我没有检查。

如何实时获取信息?另外,CheckIndex过程真的很耗时,有没有其他更好的方法来获取这两个方面的信息(索引大小和词条数)?

【问题讨论】:

    标签: java lucene


    【解决方案1】:

    我终于在Lucene In Action 2nd Edition一书中找到了答案。

    这是因为IndexReaderCheckIndex只能在commit()方法被IndexWriter调用后才能看到索引的变化。 CommitFlush 非常不同,因为 flush 只将所有缓冲的数据刷新到磁盘,而 Commit 会进行 flush 先让IndexReader 看到所有更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多