1818
1919import java .io .IOException ;
2020import java .util .ArrayList ;
21+ import java .util .Arrays ;
2122import java .util .Collection ;
2223import java .util .HashSet ;
2324import java .util .List ;
@@ -127,8 +128,10 @@ public float score(int doc, float freq) throws IOException {
127128 */
128129 public void scoreRange (DocAndFloatFeatureBuffer buffer ) throws IOException {
129130 normValues = ArrayUtil .growNoCopy (normValues , buffer .size );
130- for (int i = 0 ; i < buffer .size ; i ++) {
131- normValues [i ] = getNormValue (buffer .docs [i ]);
131+ if (norms != null ) {
132+ norms .longValues (buffer .size , buffer .docs , normValues , 1L );
133+ } else {
134+ Arrays .fill (normValues , 0 , buffer .size , 1L );
132135 }
133136 bulkScorer .score (buffer .size , buffer .features , normValues , buffer .features );
134137 }
@@ -145,6 +148,7 @@ public Explanation explain(int doc, Explanation freqExpl) throws IOException {
145148
146149 private static class MultiFieldNormValues extends NumericDocValues {
147150 private final NumericDocValues [] normsArr ;
151+ private float [] accBuf = new float [0 ];
148152 private final float [] weightArr ;
149153 private long current ;
150154 private int docID = -1 ;
@@ -193,5 +197,31 @@ public int advance(int target) {
193197 public long cost () {
194198 throw new UnsupportedOperationException ();
195199 }
200+
201+ @ Override
202+ public void longValues (int size , int [] docs , long [] values , long defaultValue )
203+ throws IOException {
204+ if (accBuf .length < size ) {
205+ accBuf = new float [ArrayUtil .oversize (size , Float .BYTES )];
206+ } else {
207+ Arrays .fill (accBuf , 0f );
208+ }
209+
210+ for (int i = 0 ; i < normsArr .length ; i ++) {
211+ normsArr [i ].longValues (size , docs , values , 0L );
212+ float weight = weightArr [i ];
213+ for (int j = 0 ; j < size ; j ++) {
214+ accBuf [j ] += weight * LENGTH_TABLE [Byte .toUnsignedInt ((byte ) values [j ])];
215+ }
216+ }
217+
218+ for (int i = 0 ; i < size ; i ++) {
219+ if (accBuf [i ] == 0f ) {
220+ values [i ] = defaultValue ;
221+ } else {
222+ values [i ] = SmallFloat .intToByte4 (Math .round (accBuf [i ]));
223+ }
224+ }
225+ }
196226 }
197227}
0 commit comments