def default_sorter_factory(search, index):
    sort_arg_name = 'sort'
    urlfield = request.values.get(sort_arg_name, '', type=str)
    if not urlfield:
        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', '')
    key, asc = parse_sort_field(urlfield)
    sort_options = current_app.config['RECORDS_REST_SORT_OPTIONS'].get(
        index, {}).get(key)
    if sort_options is None:
        return (search, {})
    search = search.sort(
        *[eval_field(f, asc) for f in sort_options['fields']]
    )
    return (search, {sort_arg_name: urlfield})