@@ -36,6 +36,7 @@ public class HybridBulkScorer extends BulkScorer {
36
36
private final float [][] windowScores ;
37
37
private final HybridQueryDocIdStream hybridQueryDocIdStream ;
38
38
private final int maxDoc ;
39
+ private int [] docIds ;
39
40
40
41
/**
41
42
* Constructor for HybridBulkScorer
@@ -45,8 +46,9 @@ public class HybridBulkScorer extends BulkScorer {
45
46
*/
46
47
public HybridBulkScorer (List <Scorer > scorers , boolean needsScores , int maxDoc ) {
47
48
long cost = 0 ;
48
- this .scorers = new Scorer [scorers .size ()];
49
- for (int subQueryIndex = 0 ; subQueryIndex < scorers .size (); subQueryIndex ++) {
49
+ int numOfQueries = scorers .size ();
50
+ this .scorers = new Scorer [numOfQueries ];
51
+ for (int subQueryIndex = 0 ; subQueryIndex < numOfQueries ; subQueryIndex ++) {
50
52
Scorer scorer = scorers .get (subQueryIndex );
51
53
if (Objects .isNull (scorer )) {
52
54
continue ;
@@ -55,12 +57,14 @@ public HybridBulkScorer(List<Scorer> scorers, boolean needsScores, int maxDoc) {
55
57
this .scorers [subQueryIndex ] = scorer ;
56
58
}
57
59
this .cost = cost ;
58
- this .hybridSubQueryScorer = new HybridSubQueryScorer (scorers . size () );
60
+ this .hybridSubQueryScorer = new HybridSubQueryScorer (numOfQueries );
59
61
this .needsScores = needsScores ;
60
62
this .matching = new FixedBitSet (WINDOW_SIZE );
61
63
this .windowScores = new float [this .scorers .length ][WINDOW_SIZE ];
62
64
this .maxDoc = maxDoc ;
63
65
this .hybridQueryDocIdStream = new HybridQueryDocIdStream (this );
66
+ this .docIds = new int [numOfQueries ];
67
+ Arrays .fill (docIds , DocIdSetIterator .NO_MORE_DOCS );
64
68
}
65
69
66
70
@ Override
@@ -69,15 +73,15 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max) thr
69
73
// making sure we are not going over the global limit defined by maxDoc
70
74
max = Math .min (max , maxDoc );
71
75
// advance all scorers to the segment's minimum doc id
72
- int [] docsIds = advance (min , scorers );
73
- while (allDocIdsUsed (docsIds , max ) == false ) {
74
- scoreWindow (collector , acceptDocs , min , max , docsIds );
76
+ advance (min , scorers );
77
+ while (allDocIdsUsed (docIds , max ) == false ) {
78
+ scoreWindow (collector , acceptDocs , min , max , docIds );
75
79
}
76
- return getNextDocIdCandidate (docsIds );
80
+ return getNextDocIdCandidate (docIds );
77
81
}
78
82
79
83
private void scoreWindow (LeafCollector collector , Bits acceptDocs , int min , int max , int [] docIds ) throws IOException {
80
- // pick the lowest out of all not yet used doc ids
84
+ // find the first document ID below the maximum threshold to establish the next scoring window boundary
81
85
int topDoc = -1 ;
82
86
for (int docId : docIds ) {
83
87
if (docId < max ) {
@@ -150,11 +154,9 @@ private void scoreWindowIntoBitSetWithSubqueryScorers(
150
154
/**
151
155
* Advance all scorers to the next document that is >= min
152
156
*/
153
- private int [] advance (int min , Scorer [] scorers ) throws IOException {
154
- int [] docIds = new int [scorers .length ];
157
+ private void advance (int min , Scorer [] scorers ) throws IOException {
155
158
for (int subQueryIndex = 0 ; subQueryIndex < scorers .length ; subQueryIndex ++) {
156
159
if (Objects .isNull (scorers [subQueryIndex ])) {
157
- docIds [subQueryIndex ] = DocIdSetIterator .NO_MORE_DOCS ;
158
160
continue ;
159
161
}
160
162
DocIdSetIterator it = scorers [subQueryIndex ].iterator ();
@@ -164,7 +166,6 @@ private int[] advance(int min, Scorer[] scorers) throws IOException {
164
166
}
165
167
docIds [subQueryIndex ] = doc ;
166
168
}
167
- return docIds ;
168
169
}
169
170
170
171
private boolean allDocIdsUsed (int [] docsIds , int max ) {
0 commit comments