@@ -58,7 +58,7 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
58
58
/**
59
59
* Set the current doc ID.
60
60
*/
61
- public abstract void setNextDocId (int docId ) throws IOException ;
61
+ public abstract boolean setNextDocId (int docId ) throws IOException ;
62
62
63
63
/**
64
64
* Return a copy of the list of the values for the current document.
@@ -124,9 +124,10 @@ public Longs(SortedNumericDocValues in) {
124
124
}
125
125
126
126
@ Override
127
- public void setNextDocId (int docId ) throws IOException {
127
+ public boolean setNextDocId (int docId ) throws IOException {
128
128
this .docId = docId ;
129
- if (in .advanceExact (docId )) {
129
+ boolean docHasValues = in .advanceExact (docId );
130
+ if (docHasValues ) {
130
131
resize (in .docValueCount ());
131
132
for (int i = 0 ; i < count ; i ++) {
132
133
values [i ] = in .nextValue ();
@@ -137,6 +138,7 @@ public void setNextDocId(int docId) throws IOException {
137
138
if (dates != null ) {
138
139
dates .setNextDocId (docId );
139
140
}
141
+ return docHasValues ;
140
142
}
141
143
142
144
/**
@@ -159,6 +161,37 @@ public long getValue() {
159
161
return values [0 ];
160
162
}
161
163
164
+ public long getMin () {
165
+ if (count == 0 ) {
166
+ return 0L ;
167
+ };
168
+ return values [0 ];
169
+ }
170
+
171
+ public long getMax () {
172
+ if (count == 0 ) {
173
+ return 0L ;
174
+ };
175
+ return values [count - 1 ];
176
+ }
177
+
178
+ public long getSum () {
179
+ if (count == 0 ) {
180
+ return 0L ;
181
+ };
182
+ long sum = 0L ;
183
+ for (int i = 0 ; i < count ; i ++)
184
+ sum += values [i ];
185
+ return sum ;
186
+ }
187
+
188
+ public double getAvg () {
189
+ if (count == 0 ) {
190
+ return 0d ;
191
+ };
192
+ return getSum () * 1.0 /count ;
193
+ }
194
+
162
195
@ Deprecated
163
196
public ReadableDateTime getDate () throws IOException {
164
197
deprecated ("getDate on numeric fields is deprecated. Use a date field to get dates." );
@@ -285,13 +318,15 @@ public int size() {
285
318
}
286
319
287
320
@ Override
288
- public void setNextDocId (int docId ) throws IOException {
289
- if (in .advanceExact (docId )) {
321
+ public boolean setNextDocId (int docId ) throws IOException {
322
+ boolean docHasValues = in .advanceExact (docId );
323
+ if (docHasValues ) {
290
324
count = in .docValueCount ();
291
325
} else {
292
326
count = 0 ;
293
327
}
294
328
refreshArray ();
329
+ return docHasValues ;
295
330
}
296
331
297
332
/**
@@ -355,15 +390,17 @@ public Doubles(SortedNumericDoubleValues in) {
355
390
}
356
391
357
392
@ Override
358
- public void setNextDocId (int docId ) throws IOException {
359
- if (in .advanceExact (docId )) {
393
+ public boolean setNextDocId (int docId ) throws IOException {
394
+ boolean docHasValues = in .advanceExact (docId );
395
+ if (docHasValues ) {
360
396
resize (in .docValueCount ());
361
397
for (int i = 0 ; i < count ; i ++) {
362
398
values [i ] = in .nextValue ();
363
399
}
364
400
} else {
365
401
resize (0 );
366
402
}
403
+ return docHasValues ;
367
404
}
368
405
369
406
/**
@@ -386,6 +423,38 @@ public double getValue() {
386
423
return values [0 ];
387
424
}
388
425
426
+ public double getMin () {
427
+ if (count == 0 ) {
428
+ return 0d ;
429
+ };
430
+ return values [0 ];
431
+ }
432
+
433
+ public double getMax () {
434
+ if (count == 0 ) {
435
+ return 0d ;
436
+ };
437
+ return values [count - 1 ];
438
+ }
439
+
440
+ public double getSum () {
441
+ if (count == 0 ) {
442
+ return 0d ;
443
+ };
444
+ double sum = 0d ;
445
+ for (int i = 0 ; i < count ; i ++)
446
+ sum += values [i ];
447
+ return sum ;
448
+ }
449
+
450
+ public double getAvg () {
451
+ if (count == 0 ) {
452
+ return 0d ;
453
+ };
454
+ return getSum () / count ;
455
+ }
456
+
457
+
389
458
@ Override
390
459
public Double get (int index ) {
391
460
return values [index ];
@@ -408,8 +477,9 @@ public GeoPoints(MultiGeoPointValues in) {
408
477
}
409
478
410
479
@ Override
411
- public void setNextDocId (int docId ) throws IOException {
412
- if (in .advanceExact (docId )) {
480
+ public boolean setNextDocId (int docId ) throws IOException {
481
+ boolean docHasValues = in .advanceExact (docId );
482
+ if (docHasValues ) {
413
483
resize (in .docValueCount ());
414
484
for (int i = 0 ; i < count ; i ++) {
415
485
GeoPoint point = in .nextValue ();
@@ -418,6 +488,7 @@ public void setNextDocId(int docId) throws IOException {
418
488
} else {
419
489
resize (0 );
420
490
}
491
+ return docHasValues ;
421
492
}
422
493
423
494
/**
@@ -528,15 +599,17 @@ public Booleans(SortedNumericDocValues in) {
528
599
}
529
600
530
601
@ Override
531
- public void setNextDocId (int docId ) throws IOException {
532
- if (in .advanceExact (docId )) {
602
+ public boolean setNextDocId (int docId ) throws IOException {
603
+ boolean docHasValues = in .advanceExact (docId );
604
+ if (docHasValues ) {
533
605
resize (in .docValueCount ());
534
606
for (int i = 0 ; i < count ; i ++) {
535
607
values [i ] = in .nextValue () == 1 ;
536
608
}
537
609
} else {
538
610
resize (0 );
539
611
}
612
+ return docHasValues ;
540
613
}
541
614
542
615
/**
@@ -584,8 +657,9 @@ abstract static class BinaryScriptDocValues<T> extends ScriptDocValues<T> {
584
657
}
585
658
586
659
@ Override
587
- public void setNextDocId (int docId ) throws IOException {
588
- if (in .advanceExact (docId )) {
660
+ public boolean setNextDocId (int docId ) throws IOException {
661
+ boolean docHasValues = in .advanceExact (docId );
662
+ if (docHasValues ) {
589
663
resize (in .docValueCount ());
590
664
for (int i = 0 ; i < count ; i ++) {
591
665
// We need to make a copy here, because BytesBinaryDVAtomicFieldData's SortedBinaryDocValues
@@ -596,6 +670,7 @@ public void setNextDocId(int docId) throws IOException {
596
670
} else {
597
671
resize (0 );
598
672
}
673
+ return docHasValues ;
599
674
}
600
675
601
676
/**
0 commit comments