关闭

【Lucene】IndexReader类的maxDoc()与numDocs()的区别

标签: luceneindex搜索引擎索引
1647人阅读 评论(2) 收藏 举报
分类:

http://hi.baidu.com/sunky/item/31fdfef9ad1a9d763d198b47


1)Let us see the difference in the comment of  Class IndexReader

  /** Returns the number of documents in this index. */
  public abstract int numDocs();

  /** Returns one greater than the largest possible document number.
   This may be used to, e.g., determine how big to allocate an array which
   will have an element for every document number in an index.
   */
  public abstract int maxDoc();

2) Actually, the real code to implement is the best explanation. The implemetation Class of IndexReader is SegmentReader. Let us see theire implementations as below:

  public final int maxDoc() {
    return fieldsReader.size();
  }

  public final int numDocs() {
    int n = maxDoc();
    if (deletedDocs != null)
      n -= deletedDocs.count();
    return n;
  }

  I think it is easy to understand the reason now !

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:52883次
    • 积分:757
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:47篇
    • 译文:0篇
    • 评论:3条
    最新评论