def extract_filters(term, opts=None):
    """
    Pulls all the filtering options out of the term and returns a cleaned term
    and a dictionary of filter names and filter values. Term filters override
    filters found in opts.
    """

    opts = opts or {}
    filters = {}
    params = {}

    # Type filters.
    term, addon_type = extract_from_query(term, 'type', '\w+')
    addon_type = addon_type or opts.get('addon_type')
    if addon_type:
        try:
            atype = int(addon_type)
            if atype in amo.ADDON_SEARCH_TYPES:
                filters['type'] = atype
        except __HOLE__:
            # `addon_type` is not a digit.
            # Try to find it in `ADDON_SEARCH_SLUGS`.
            atype = amo.ADDON_SEARCH_SLUGS.get(addon_type.lower())
            if atype:
                filters['type'] = atype

    # Platform filters.
    term, platform = extract_from_query(term, 'platform', '\w+')
    params['platform'] = platform or opts.get('platform')

    # Version filters.
    term, version = extract_from_query(term, 'version', '[0-9.]+')
    params['version'] = version or opts.get('version')

    # Tag filters.
    term, tag = extract_from_query(term, 'tag', '\w+')
    if tag:
        tag = Tag.objects.filter(tag_text=tag).values_list('tag_text',
                                                           flat=True)
        if tag:
            filters['tags__in'] = list(tag)

    return (term, filters, params)
dataset/ETHPy150Open mozilla/addons-server/src/olympia/legacy_api/utils.py/extract_filters