def fix_search_query(query, extra_params=None):
    rv = dict((smart_str(k), v) for k, v in query.items())
    changed = False
    # Change old keys to new names.
    keys = {
        'lver': 'appver',
        'pid': 'platform',
    }
    for old, new in keys.items():
        if old in query:
            rv[new] = rv.pop(old)
            changed = True

    # Change old parameter values to new values.
    params = {
        'sort': {
            'newest': 'updated',
            'popularity': 'downloads',
            'weeklydownloads': 'users',
            'averagerating': 'rating',
            'sortby': 'sort',
        },
        'platform': dict((str(p.id), p.shortname)
                         for p in amo.PLATFORMS.values())
    }
    if extra_params:
        params.update(extra_params)
    for key, fixes in params.items():
        if key in rv and rv[key] in fixes:
            rv[key] = fixes[rv[key]]
            changed = True
    return rv if changed else query
dataset/ETHPy150Open mozilla/addons-server/src/olympia/search/views.py/fix_search_query/original