nodes: 0, module; 1, function_definition; 2, function_name:geolocation_sort; 3, parameters; 4, block; 5, identifier:field_name; 6, identifier:argument; 7, identifier:unit; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, function_definition; 12, return_statement; 13, identifier:mode; 14, None; 15, identifier:distance_type; 16, None; 17, comment:"""Sort field factory for geo-location based sorting.
  
      :param argument: Name of URL query string field to parse pin location from.
          Multiple locations can be provided. Each location can be either a
          string "latitude,longitude" or a geohash.
      :param unit: Distance unit (e.g. km).
      :param mode: Sort mode (avg, min, max).
      :param distance_type: Distance calculation mode.
      :returns: Function that returns geolocation sort field.
      """; 18, function_name:inner; 19, parameters; 20, block; 21, identifier:inner; 22, identifier:asc; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, if_statement; 27, return_statement; 28, assignment; 29, assignment; 30, identifier:mode; 31, block; 32, identifier:distance_type; 33, block; 34, identifier:field; 35, identifier:locations; 36, call; 37, identifier:field; 38, dictionary; 39, expression_statement; 40, expression_statement; 41, attribute; 42, argument_list; 43, pair; 44, assignment; 45, assignment; 46, attribute; 47, identifier:getlist; 48, identifier:argument; 49, keyword_argument; 50, string; 51, dictionary; 52, subscript; 53, identifier:mode; 54, subscript; 55, identifier:distance_type; 56, identifier:request; 57, identifier:values; 58, identifier:type; 59, identifier:str; 60, string_content:_geo_distance; 61, pair; 62, pair; 63, pair; 64, subscript; 65, string; 66, subscript; 67, string; 68, identifier:field_name; 69, identifier:locations; 70, string; 71, conditional_expression:'asc' if asc else 'desc'; 72, string; 73, identifier:unit; 74, identifier:field; 75, string; 76, string_content:mode; 77, identifier:field; 78, string; 79, string_content:distance_type; 80, string_content:order; 81, string; 82, identifier:asc; 83, string; 84, string_content:unit; 85, string_content:_geo_distance; 86, string_content:_geo_distance; 87, string_content:asc; 88, string_content:desc
code: def geolocation_sort(field_name, argument, unit, mode=None,
                       distance_type=None):
      """Sort field factory for geo-location based sorting.
  
      :param argument: Name of URL query string field to parse pin location from.
          Multiple locations can be provided. Each location can be either a
          string "latitude,longitude" or a geohash.
      :param unit: Distance unit (e.g. km).
      :param mode: Sort mode (avg, min, max).
      :param distance_type: Distance calculation mode.
      :returns: Function that returns geolocation sort field.
      """
      def inner(asc):
          locations = request.values.getlist(argument, type=str)
          field = {
              '_geo_distance': {
                  field_name: locations,
                  'order': 'asc' if asc else 'desc',
                  'unit': unit,
              }
          }
          if mode:
              field['_geo_distance']['mode'] = mode
          if distance_type:
              field['_geo_distance']['distance_type'] = distance_type
          return field
      return inner