jpountz commented on code in PR #13199: URL: https://github.com/apache/lucene/pull/13199#discussion_r1538951789
########## lucene/core/src/java/org/apache/lucene/index/PointValues.java: ########## @@ -375,16 +375,23 @@ private void intersect(IntersectVisitor visitor, PointTree pointTree) throws IOE public final long estimatePointCount(IntersectVisitor visitor) { try { final PointTree pointTree = getPointTree(); - final long count = estimatePointCount(visitor, pointTree); + final long count = estimatePointCount(visitor, pointTree, Long.MAX_VALUE); assert pointTree.moveToParent() == false; return count; } catch (IOException ioe) { throw new UncheckedIOException(ioe); } } - private long estimatePointCount(IntersectVisitor visitor, PointTree pointTree) - throws IOException { + /** + * Estimate the number of documents that would be matched by {@link #intersect} with the given + * {@link IntersectVisitor}. The estimation will terminate when the point count exceeds the upper + * bound. + * + * <p>TODO: Broad-first will help extimation terminate earlier? + */ + public static long estimatePointCount( Review Comment: Nit: To make contracts of these functions clearer, I'd rather make this function private, and them have another `isEstimatedPointCountGreaterThanOrEqualTo` public function (and probably tagged with `@lucene.internal` so that we can evolve it as we want) that calls this private function? ########## lucene/core/src/java/org/apache/lucene/index/PointValues.java: ########## @@ -398,8 +405,8 @@ private long estimatePointCount(IntersectVisitor visitor, PointTree pointTree) if (pointTree.moveToChild()) { long cost = 0; do { - cost += estimatePointCount(visitor, pointTree); - } while (pointTree.moveToSibling()); + cost += estimatePointCount(visitor, pointTree, upperBound - cost); + } while (cost <= upperBound && pointTree.moveToSibling()); Review Comment: I believe that we can stop counting if `cost == upperBound`? ```suggestion } while (cost < upperBound && pointTree.moveToSibling()); ``` ########## lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java: ########## @@ -301,6 +303,14 @@ public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue updateSkipInterval(true); } + private PointValues.PointTree pointTree() throws IOException { + if (pointTree == null) { + pointTree = pointValues.getPointTree(); + } + assert !pointTree.moveToParent(); + return pointTree; + } Review Comment: What about pulling the point tree in the constructor instead of doing it lazily (for simplicity)? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org