'Map a search query to it\'s short-hand URL, using Tag prefixes if
there is exactly one tag in the search terms or we have tag context.
>>> urlmap.url_search([\'foo\', \'bar\', \'baz\'])
\'/search/?q=foo%20bar%20baz\'
>>> urlmap.url_search([\'foo\', \'tag:Inbox\', \'wtf\'], output=\'json\')
\'/in/inbox/as.json?q=foo%20wtf\'
>>> urlmap.url_search([\'foo\', \'in:Inbox\', \'wtf\'], output=\'json\')
\'/in/inbox/as.json?q=foo%20wtf\'
>>> urlmap.url_search([\'foo\', \'in:Inbox\', \'tag:New\'], output=\'xml\')
\'/search/as.xml?q=foo%20in%3AInbox%20tag%3ANew\'
>>> urlmap.url_search([\'foo\', \'tag:Inbox\', \'in:New\'], tag=\'Inbox\')
\'/in/inbox/?q=foo%20in%3ANew\''

def url_search(self, search_terms, tag=None, output=''):

    tags = ((tag and [tag]) or [t for t in search_terms if (t.startswith('tag:') or t.startswith('in:'))])
    if (len(tags) == 1):
        prefix = self.url_tag(tags[0].replace('tag:', '').replace('in:', ''))
        search_terms = [t for t in search_terms if ((t not in tags) and (t.replace('tag:', '').replace('in:', '') not in tags))]
    else:
        prefix = '/search/'
    return self._url(prefix, output, ('q=' + quote('    '.join(search_terms))))
