@@ -375,7 +375,7 @@ public int resetPostingsScorer(long offset) throws IOException {
375375 return vectors ;
376376 }
377377
378- float scoreIndividually (int offset ) throws IOException {
378+ private float scoreIndividually (int offset ) throws IOException {
379379 float maxScore = Float .NEGATIVE_INFINITY ;
380380 // score individually, first the quantized byte chunk
381381 for (int j = 0 ; j < BULK_SIZE ; j ++) {
@@ -419,27 +419,25 @@ float scoreIndividually(int offset) throws IOException {
419419 return maxScore ;
420420 }
421421
422- private static int filterDocs (int [] docIds , int offset , IntPredicate needsScoring ) {
423- int filtered = 0 ;
422+ private static int docToBulkScore (int [] docIds , int offset , IntPredicate needsScoring ) {
423+ int docToScore = ES91OSQVectorsScorer . BULK_SIZE ;
424424 for (int i = 0 ; i < ES91OSQVectorsScorer .BULK_SIZE ; i ++) {
425- if (needsScoring .test (docIds [offset + i ]) == false ) {
426- docIds [offset + i ] = -1 ;
427- filtered ++;
425+ final int idx = offset + i ;
426+ if (needsScoring .test (docIds [idx ]) == false ) {
427+ docIds [idx ] = -1 ;
428+ docToScore --;
428429 }
429430 }
430- return filtered ;
431+ return docToScore ;
431432 }
432433
433- private static int collect (int [] docIds , int offset , KnnCollector knnCollector , float [] scores ) {
434- int scoredDocs = 0 ;
434+ private static void collectBulk (int [] docIds , int offset , KnnCollector knnCollector , float [] scores ) {
435435 for (int i = 0 ; i < ES91OSQVectorsScorer .BULK_SIZE ; i ++) {
436- int doc = docIds [offset + i ];
436+ final int doc = docIds [offset + i ];
437437 if (doc != -1 ) {
438- scoredDocs ++;
439438 knnCollector .collect (doc , scores [i ]);
440439 }
441440 }
442- return scoredDocs ;
443441 }
444442
445443 @ Override
@@ -449,14 +447,14 @@ public int visit(KnnCollector knnCollector) throws IOException {
449447 int limit = vectors - BULK_SIZE + 1 ;
450448 int i = 0 ;
451449 for (; i < limit ; i += BULK_SIZE ) {
452- int docsToScore = BULK_SIZE - filterDocs (docIdsScratch , i , needsScoring );
453- if (docsToScore == 0 ) {
450+ final int docsToBulkScore = docToBulkScore (docIdsScratch , i , needsScoring );
451+ if (docsToBulkScore == 0 ) {
454452 continue ;
455453 }
456454 quantizeQueryIfNecessary ();
457455 indexInput .seek (slicePos + i * quantizedByteLength );
458- float maxScore = Float . NEGATIVE_INFINITY ;
459- if (docsToScore < BULK_SIZE / 2 ) {
456+ final float maxScore ;
457+ if (docsToBulkScore < BULK_SIZE / 2 ) {
460458 maxScore = scoreIndividually (i );
461459 } else {
462460 maxScore = osqVectorsScorer .scoreBulk (
@@ -471,8 +469,9 @@ public int visit(KnnCollector knnCollector) throws IOException {
471469 );
472470 }
473471 if (knnCollector .minCompetitiveSimilarity () < maxScore ) {
474- scoredDocs += collect (docIdsScratch , i , knnCollector , scores );
472+ collectBulk (docIdsScratch , i , knnCollector , scores );
475473 }
474+ scoredDocs += docsToBulkScore ;
476475 }
477476 // process tail
478477 for (; i < vectors ; i ++) {
0 commit comments