def extract_filters(term, opts=None):
 opts = (opts or {})
 filters = {}
 params = {}
 (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 ValueError:
   atype = amo.ADDON_SEARCH_SLUGS.get(addon_type.lower())
   if atype:
    filters['type'] = atype
 (term, platform) = extract_from_query(term, 'platform', '\\w+')
 params['platform'] = (platform or opts.get('platform'))
 (term, version) = extract_from_query(term, 'version', '[0-9.]+')
 params['version'] = (version or opts.get('version'))
 (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)

def extract_filters ( term , opts = None ) : opts = ( opts or { } ) filters = { } params = { } ( 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 ValueError : atype = amo . ADDON_SEARCH_SLUGS . get ( addon_type . lower ( ) ) if atype : filters [ 'type' ] = atype ( term , platform ) = extract_from_query ( term , 'platform' , '\\w+' ) params [ 'platform' ] = ( platform or opts . get ( 'platform' ) ) ( term , version ) = extract_from_query ( term , 'version' , '[0-9.]+' ) params [ 'version' ] = ( version or opts . get ( 'version' ) ) ( 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 )
pulls all the filtering options out of the term and returns a cleaned term and a dictionary of filter names and filter values .