jpountz commented on a change in pull request #905: LUCENE-8990: Add estimateDocCount(visitor) method to PointValues URL: https://github.com/apache/lucene-solr/pull/905#discussion_r331178088
########## File path: lucene/core/src/test/org/apache/lucene/codecs/lucene60/TestLucene60PointsFormat.java ########## @@ -385,12 +298,102 @@ public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { } return Relation.CELL_CROSSES_QUERY; } - }); + }; + // If only one point matches, then the point count is (actualMaxPointsInLeafNode + 1) / 2 + // in general, or maybe 2x that if the point is a split value + final long pointCount = points.estimatePointCount(onePointMatchVisitor); + assertTrue(""+pointCount, + pointCount == (actualMaxPointsInLeafNode + 1) / 2 || // common case + pointCount == 2*((actualMaxPointsInLeafNode + 1) / 2)); // if the point is a split value - assertTrue(""+docCount, - docCount == Math.ceil(((actualMaxPointsInLeafNode + 1) / 2) / pointsPerDocument) || // common case - docCount == Math.ceil((2*((actualMaxPointsInLeafNode + 1) / 2)) / pointsPerDocument)); // if the point is a split value + final long docCount = points.estimateDocCount(onePointMatchVisitor); + if (multiValues) { + assertEquals(docCount, (long) (docCount * (1d - Math.pow( (numDocs - pointCount) / points.size() , points.size() / docCount)))); + } else { + assertEquals(pointCount, docCount); + } r.close(); dir.close(); } + + public void testDocCountEdgeCases() { + PointValues values = getPointValues(Long.MAX_VALUE, 1, Long.MAX_VALUE); + long docs = values.estimateDocCount(null); + assertEquals(1, docs); + values = getPointValues(Long.MAX_VALUE, 1, 1); + docs = values.estimateDocCount(null); + assertEquals(1, docs); + values = getPointValues(Long.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE); + docs = values.estimateDocCount(null); + assertEquals(Integer.MAX_VALUE, docs); + values = getPointValues(Long.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE / 2); + docs = values.estimateDocCount(null); + assertEquals(Integer.MAX_VALUE, docs); + values = getPointValues(Long.MAX_VALUE, Integer.MAX_VALUE, 1); + docs = values.estimateDocCount(null); + assertEquals(1, docs); + } + + public void testRandomDocCount() { + for (int i = 0; i < 100; i++) { + long size = TestUtil.nextLong(random(), 1, Long.MAX_VALUE); + int maxDoc = (size > Integer.MAX_VALUE) ? Integer.MAX_VALUE : Math.toIntExact(size); + int docCount = TestUtil.nextInt(random(), 1, maxDoc); + long estimatePointCount = TestUtil.nextLong(random(), 0, size); + PointValues values = getPointValues(size, docCount, estimatePointCount); + long docs = values.estimateDocCount(null); + assertTrue(docs <= estimatePointCount); + assertTrue(docs <= maxDoc); Review comment: maybe also assert that `docs >= estimatedPointCount / (size/docCount)`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org