川在路上

个人博客: http://zhangxichuan.science

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

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 !

阅读更多
个人分类: 搜索引擎
上一篇Heritrix各个类说明
下一篇java在指定路径下创建文件,并写入文件内容
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭