'" Returns a list of results from DuckDuckGo for the given query.'

def search(self, query, type=SEARCH, start=None, count=None, sort=RELEVANCY, size=None, cached=True, **kwargs):

    if (type != SEARCH):
        raise SearchEngineTypeError
    url = URL(DUCKDUCKGO, method=GET, query={'q': query, 'o': 'json'})
    if ((type == SEARCH) and (self.language is not None)):
        url.query['kl'] = self.language
    kwargs.setdefault('unicode', True)
    kwargs.setdefault('throttle', self.throttle)
    data = url.download(cached=cached, **kwargs)
    data = json.loads(data)
    results = Results(DUCKDUCKGO, query, type)
    results.total = None
    for x in data.get('Results', []):
        if x.get('FirstURL'):
            r = Result(url=None)
            r.url = self.format(x.get('FirstURL'))
            r.title = self.format(data.get('Heading'))
            r.text = self.format(data.get('Abstract'))
            r.author = self.format(data.get('AbstractSource'))
            r.type = self.format(REFERENCE)
            results.append(r)
    for topic in data.get('RelatedTopics', []):
        for x in topic.get('Topics', [topic]):
            r = Result(url=None)
            r.url = x.get('FirstURL')
            m = re.match('^http://duckduckgo.com/([a-z]/)?(.*?)(\\?|$)', r.url)
            s1 = ((m and m.group(2)) or '')
            s1 = u(decode_url(s1.encode('utf-8')))
            s1 = s1.strip().replace('_', '    ')
            s1 = (s1[:1].upper() + s1[1:])
            s2 = x.get('Text', '').strip()
            s2 = re.sub('    +', '    ', s2)
            s2 = ((s2[:1].upper() + s2[1:]) or '')
            s2 = ((s2.startswith(s1) and ('<a    href="%s">%s</a>%s' % (r.url, s1, s2[len(s1):]))) or re.sub('^(.*?)(    -    |    or    |,    )(.*?)', ('<a    href="%s">\\1</a>\\2\\3' % r.url), s2))
            s3 = ((m and m.group(1)) or '')
            s3 = {'c': CATEGORY, 'd': DEFINITION}.get(s3.rstrip('/'), '')
            s3 = (topic.get('Name', '').lower() or s3)
            s3 = re.sub('^in    ', '', s3)
            r.url = self.format(r.url)
            r.title = self.format(s1)
            r.text = self.format(s2)
            r.type = self.format(s3)
            results.append(r)
    return results
