@@ -434,7 +434,7 @@ public static FieldSortBuilder getPrimaryFieldSortOrNull(SearchSourceBuilder sou
434
434
* {@link SortField}. This is needed for {@link SortField} that converts values from one type to another using
435
435
* {@link FieldSortBuilder#setNumericType(String)} )} (e.g.: long to double).
436
436
*/
437
- private static Function <byte [], Comparable > numericPointConverter (SortField sortField , NumberFieldType numberFieldType ) {
437
+ private static Function <byte [], Comparable <?> > numericPointConverter (SortField sortField , NumberFieldType numberFieldType ) {
438
438
switch (IndexSortConfig .getSortFieldType (sortField )) {
439
439
case LONG :
440
440
return v -> numberFieldType .parsePoint (v ).longValue ();
@@ -457,7 +457,7 @@ private static Function<byte[], Comparable> numericPointConverter(SortField sort
457
457
* Return a {@link Function} that converts a serialized date point into a {@link Long} according to the provided
458
458
* {@link NumericType}.
459
459
*/
460
- private static Function <byte [], Comparable > datePointConverter (DateFieldType dateFieldType , String numericTypeStr ) {
460
+ private static Function <byte [], Comparable <?> > datePointConverter (DateFieldType dateFieldType , String numericTypeStr ) {
461
461
if (numericTypeStr != null ) {
462
462
NumericType numericType = resolveNumericType (numericTypeStr );
463
463
if (dateFieldType .resolution () == MILLISECONDS && numericType == NumericType .DATE_NANOSECONDS ) {
@@ -491,7 +491,7 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
491
491
case INT :
492
492
case DOUBLE :
493
493
case FLOAT :
494
- final Function <byte [], Comparable > converter ;
494
+ final Function <byte [], Comparable <?> > converter ;
495
495
if (fieldType instanceof NumberFieldType ) {
496
496
converter = numericPointConverter (sortField , (NumberFieldType ) fieldType );
497
497
} else if (fieldType instanceof DateFieldType ) {
@@ -502,9 +502,7 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
502
502
if (PointValues .size (reader , fieldName ) == 0 ) {
503
503
return null ;
504
504
}
505
- final Comparable min = converter .apply (PointValues .getMinPackedValue (reader , fieldName ));
506
- final Comparable max = converter .apply (PointValues .getMaxPackedValue (reader , fieldName ));
507
- return MinAndMax .newMinMax (min , max );
505
+ return extractMinAndMax (reader , fieldName , converter );
508
506
509
507
case STRING :
510
508
case STRING_VAL :
@@ -520,6 +518,14 @@ public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortB
520
518
return null ;
521
519
}
522
520
521
+ @ SuppressWarnings ("unchecked" )
522
+ private static <T extends Comparable <T >> MinAndMax <T > extractMinAndMax (IndexReader reader , String fieldName ,
523
+ Function <byte [], Comparable <?>> converter ) throws IOException {
524
+ final T min = (T )converter .apply (PointValues .getMinPackedValue (reader , fieldName ));
525
+ final T max = (T )converter .apply (PointValues .getMaxPackedValue (reader , fieldName ));
526
+ return MinAndMax .newMinMax (min , max );
527
+ }
528
+
523
529
/**
524
530
* Throws an exception if max children is not located at top level nested sort.
525
531
*/
@@ -601,12 +607,12 @@ public static FieldSortBuilder fromXContent(XContentParser parser, String fieldN
601
607
private static final ObjectParser <FieldSortBuilder , Void > PARSER = new ObjectParser <>(NAME );
602
608
603
609
static {
604
- PARSER .declareField (FieldSortBuilder ::missing , p -> p . objectText () , MISSING , ValueType .VALUE );
610
+ PARSER .declareField (FieldSortBuilder ::missing , XContentParser :: objectText , MISSING , ValueType .VALUE );
605
611
PARSER .declareString (FieldSortBuilder ::unmappedType , UNMAPPED_TYPE );
606
612
PARSER .declareString ((b , v ) -> b .order (SortOrder .fromString (v )) , ORDER_FIELD );
607
613
PARSER .declareString ((b , v ) -> b .sortMode (SortMode .fromString (v )), SORT_MODE );
608
614
PARSER .declareObject (FieldSortBuilder ::setNestedSort , (p , c ) -> NestedSortBuilder .fromXContent (p ), NESTED_FIELD );
609
- PARSER .declareString (( b , v ) -> b . setNumericType ( v ) , NUMERIC_TYPE );
615
+ PARSER .declareString (FieldSortBuilder :: setNumericType , NUMERIC_TYPE );
610
616
}
611
617
612
618
@ Override
0 commit comments