//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)得到的结果不一致呢?
0 个回复