gf2121 commented on code in PR #14704: URL: https://github.com/apache/lucene/pull/14704#discussion_r2104631515
########## lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java: ########## @@ -229,7 +249,39 @@ public float score(float freq, long encodedNorm) { // Finally we expand weight * (1 - 1 / (1 + freq * 1/norm)) to // weight - weight / (1 + freq * 1/norm), which runs slightly faster. float normInverse = cache[((byte) encodedNorm) & 0xFF]; - return weight - weight / (1f + freq * normInverse); + return score(freq, normInverse); + } + + @Override + public void score(DocAndFreqBuffer buffer, NumericDocValues norms, float[] scores) + throws IOException { + if (norms == null) { + float normInverse = cache[1]; + // The below loop should auto-vectorize. + for (int i = 0; i < buffer.size; ++i) { + scores[i] = score(buffer.freqs[i], normInverse); + } + } else { + if (normInverses == null || normInverses.length < buffer.size) { + normInverses = new float[ArrayUtil.oversize(buffer.size, Float.BYTES)]; Review Comment: Do we need this new array or we can just reuse `scores`? ########## lucene/core/src/java/org/apache/lucene/search/similarities/Similarity.java: ########## @@ -208,6 +211,29 @@ protected SimScorer() {} */ public abstract float score(float freq, long norm); + /** + * Bulk computation of scores. For each entry in the given {@code buffer}, compute the score of + * the document and set its value in the {@code scores} array at the same index. + * + * <p><b>NOTE</b>: Doc IDs must be sorted, with no duplicates. Review Comment: Should we override it in `AssertingSimilarity` to check these limitations? -- 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