居然是你

lucene count奇怪的问题

Lucene | 作者 codepub | 发布于2017年11月30日 | 阅读数:2976

//SpanNearQuery query
weight = query.createWeight(indexSearcher, false);
List<LeafReaderContext> leaves = indexSearcher.getIndexReader().leaves();
int count = 0;
Spans spans;
int docCount = 0;
for (LeafReaderContext leaf : leaves) {
spans = weight.getSpans(leaf, SpanWeight.Postings.POSITIONS);
while (spans != null && spans.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
while (spans.nextStartPosition() != spans.NO_MORE_POSITIONS) {
count++;
}
docCount++;
}
}
System.out.println("hits count = " + docCount);
为什么用这种方式统计的Doc count和IndexSearcher.count(query)得到的结果不一致呢?
已邀请:

要回复问题请先登录注册