code: def default_sorter_factory(search, index):
      
      sort_arg_name = 'sort'
      urlfield = request.values.get(sort_arg_name, '', type=str)
  
      # Get default sorting if sort is not specified.
      if not urlfield:
          # cast to six.text_type to handle unicodes in Python 2
          has_query = request.values.get('q', type=six.text_type)
          urlfield = current_app.config['RECORDS_REST_DEFAULT_SORT'].get(
              index, {}).get('query' if has_query else 'noquery', '')
  
      # Parse sort argument
      key, asc = parse_sort_field(urlfield)
  
      # Get sort options
      sort_options = current_app.config['RECORDS_REST_SORT_OPTIONS'].get(
          index, {}).get(key)
      if sort_options is None:
          return (search, {})
  
      # Get fields to sort query by
      search = search.sort(
          *[eval_field(f, asc) for f in sort_options['fields']]
      )
      return (search, {sort_arg_name: urlfield})
docs: Default sort query factory.
  
      :param query: Search query.
      :param index: Index to search in.
      :returns: Tuple of (query, URL arguments).