HUSTERGS commented on code in PR #14970: URL: https://github.com/apache/lucene/pull/14970#discussion_r2227361233
########## lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java: ########## @@ -391,7 +392,46 @@ private static int slowFindNextGEQ(int[] buffer, int length, int target, int fro return length; } - public void testFilterByScore() { + public void testFilterByFloatScore() { + for (int iter = 0; iter < 1_000; ++iter) { + int padding = TestUtil.nextInt(random(), 0, 5); + DocAndFloatFeatureBuffer b1 = new DocAndFloatFeatureBuffer(); + DocAndFloatFeatureBuffer b2 = new DocAndFloatFeatureBuffer(); + b1.growNoCopy(128 + padding); + b2.growNoCopy(128 + padding); + + int doc = 0; + for (int i = 0; i < 128 + padding; ++i) { + doc += TestUtil.nextInt(random(), 1, 1000); + b1.docs[i] = b2.docs[i] = doc; + b1.features[i] = b2.features[i] = random().nextFloat(); + } + + float minScoreInclusive = random().nextFloat(); + int upTo = TestUtil.nextInt(random(), 0, 127); + b1.size = slowFilterByScore(b1.docs, b1.features, minScoreInclusive, upTo); + b2.size = VectorUtil.filterByScore(b2.docs, b2.features, minScoreInclusive, upTo); + assertEquals(b1.size, b2.size); + assertTrue(Arrays.equals(b1.docs, 0, b1.size, b2.docs, 0, b2.size)); + // two double array should be exactly the same, so just use simple Arrays.equals Review Comment: nit: should be float array? ########## lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java: ########## @@ -138,6 +138,34 @@ static double minRequiredScore( return minRequiredScore; } + /** + * Filters competitive hits from the provided {@link DocAndFloatFeatureBuffer}. + * + * <p>This method removes documents from the buffer that cannot possibly have a score competitive + * enough to exceed the minimum competitive score, given the maximum remaining score and the + * number of scorers. + */ + static void filterCompetitiveHits( + DocAndFloatFeatureBuffer buffer, + double maxRemainingScore, + float minCompetitiveScore, + int numScorers) { + double minRequiredScoreDouble = + minRequiredScore(maxRemainingScore, minCompetitiveScore, numScorers); + float minRequiredScore = (float) minRequiredScoreDouble; Review Comment: nit: would it be better if we rename the `minRequiredScore` to `minRequiredScoreFloat`? -- 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