question: static Sort parseSort ( long timestampSec , IndexState state , List < Object > fields , List < String > sortFieldNames , Map < String , FieldDef > dynamicFields ) { List < SortField > sortFields = new ArrayList < SortField > ( ) ; for ( Object _sub : fields ) { Request sub = ( Request ) _sub ; String fieldName = sub . getString ( "field" ) ; SortField sf ; if ( sortFieldNames != null ) { sortFieldNames . add ( fieldName ) ; } if ( fieldName . equals ( "docid" ) ) { sf = SortField . FIELD_DOC ; } else if ( fieldName . equals ( "score" ) ) { sf = SortField . FIELD_SCORE ; } else { FieldDef fd ; if ( dynamicFields != null ) { fd = dynamicFields . get ( fieldName ) ; } else { fd = null ; } if ( fd == null ) { fd = state . getField ( fieldName ) ; } if ( fd == null ) { sub . fail ( "field" , "field \"" + fieldName + "\" was not registered and was not specified as a dynamicField" ) ; fd = null ; } if ( fd . valueSource != null ) { sf = fd . valueSource . getSortField ( sub . getBoolean ( "reverse" ) ) ; } else if ( fd . valueType == FieldDef . FieldValueType . LAT_LON ) { if ( fd . fieldType . docValuesType ( ) == DocValuesType . NONE ) { sub . fail ( "field" , "field \"" + fieldName + "\" was not registered with sort=true" ) ; } Request sub2 = sub . getStruct ( "origin" ) ; sf = LatLonDocValuesField . newDistanceSort ( fieldName , sub2 . getDouble ( "latitude" ) , sub2 . getDouble ( "longitude" ) ) ; } else { if ( ( fd . fieldType != null && fd . fieldType . docValuesType ( ) == DocValuesType . NONE ) || ( fd . fieldType == null && fd . valueSource == null ) ) { sub . fail ( "field" , "field \"" + fieldName + "\" was not registered with sort=true" ) ; } if ( fd . multiValued ) { String selectorString = sub . getEnum ( "selector" ) ; if ( fd . valueType == FieldDef . FieldValueType . ATOM ) { SortedSetSelector . Type selector ; if ( selectorString . equals ( "min" ) ) { selector = SortedSetSelector . Type . MIN ; } else if ( selectorString . equals ( "max" ) ) { selector = SortedSetSelector . Type . MAX ; } else if ( selectorString . equals ( "middle_min" ) ) { selector = SortedSetSelector . Type . MIDDLE_MIN ; } else if ( selectorString . equals ( "middle_max" ) ) { selector = SortedSetSelector . Type . MIDDLE_MAX ; } else { assert false ; selector = null ; } sf = new SortedSetSortField ( fieldName , sub . getBoolean ( "reverse" ) , selector ) ; } else if ( fd . valueType == FieldDef . FieldValueType . INT ) { sf = new SortedNumericSortField ( fieldName , SortField . Type . INT , sub . getBoolean ( "reverse" ) , parseNumericSelector ( sub , selectorString ) ) ; } else if ( fd . valueType == FieldDef . FieldValueType . LONG ) { sf = new SortedNumericSortField ( fieldName , SortField . Type . LONG , sub . getBoolean ( "reverse" ) , parseNumericSelector ( sub , selectorString ) ) ; } else if ( fd . valueType == FieldDef . FieldValueType . FLOAT ) { sf = new SortedNumericSortField ( fieldName , SortField . Type . FLOAT , sub . getBoolean ( "reverse" ) , parseNumericSelector ( sub , selectorString ) ) ; } else if ( fd . valueType == FieldDef . FieldValueType . DOUBLE ) { sf = new SortedNumericSortField ( fieldName , SortField . Type . DOUBLE , sub . getBoolean ( "reverse" ) , parseNumericSelector ( sub , selectorString ) ) ; } else { sub . fail ( "field" , "cannot sort by multiValued field \"" + fieldName + "\": type is " + fd . valueType ) ; assert false ; sf = null ; } } else { SortField . Type sortType ; if ( fd . valueType == FieldDef . FieldValueType . ATOM ) { sortType = SortField . Type . STRING ; } else if ( fd . valueType == FieldDef . FieldValueType . LONG || fd . valueType == FieldDef . FieldValueType . DATE_TIME ) { sortType = SortField . Type . LONG ; } else if ( fd . valueType == FieldDef . FieldValueType . INT ) { sortType = SortField . Type . INT ; } else if ( fd . valueType == FieldDef . FieldValueType . DOUBLE ) { sortType = SortField . Type . DOUBLE ; } else if ( fd . valueType == FieldDef . FieldValueType . FLOAT ) { sortType = SortField . Type . FLOAT ; } else { sub . fail ( "field" , "cannot sort by field \"" + fieldName + "\": type is " + fd . valueType ) ; assert false ; sortType = null ; } sf = new SortField ( fieldName , sortType , sub . getBoolean ( "reverse" ) ) ; } } boolean hasMissingLast = sub . hasParam ( "missingLast" ) ; boolean missingLast = sub . getBoolean ( "missingLast" ) ; if ( fd . valueType == FieldDef . FieldValueType . ATOM ) { if ( missingLast ) { sf . setMissingValue ( SortField . STRING_LAST ) ; } else { sf . setMissingValue ( SortField . STRING_FIRST ) ; } } else if ( fd . valueType == FieldDef . FieldValueType . INT ) { sf . setMissingValue ( missingLast ? Integer . MAX_VALUE : Integer . MIN_VALUE ) ; } else if ( fd . valueType == FieldDef . FieldValueType . LONG ) { sf . setMissingValue ( missingLast ? Long . MAX_VALUE : Long . MIN_VALUE ) ; } else if ( fd . valueType == FieldDef . FieldValueType . FLOAT ) { sf . setMissingValue ( missingLast ? Float . POSITIVE_INFINITY : Float . NEGATIVE_INFINITY ) ; } else if ( fd . valueType == FieldDef . FieldValueType . DOUBLE ) { sf . setMissingValue ( missingLast ? Double . POSITIVE_INFINITY : Double . NEGATIVE_INFINITY ) ; } else if ( hasMissingLast ) { sub . fail ( "missingLast" , "field=" + fieldName + ": can only specify missingLast for string and numeric field types: got SortField type " + sf . getType ( ) ) ; } } sortFields . add ( sf ) ; } return new Sort ( sortFields . toArray ( new SortField [ sortFields . size ( ) ] ) ) ; }
target:  Decodes a list of Request into the corresponding Sort. 