def _build_suggestions(request, cat, suggester):
    results = []
    q = request.GET.get('q')
    if q and (q.isdigit() or len(q) > 2):
        q_ = q.lower()

        if cat != 'apps':
            # Applications.
            for a in amo.APP_USAGE:
                name_ = unicode(a.pretty).lower()
                word_matches = [w for w in q_.split() if name_ in w]
                if q_ in name_ or word_matches:
                    results.append({
                        'id': a.id,
                        'name': _(u'{0} Add-ons').format(a.pretty),
                        'url': locale_url(a.short),
                        'cls': 'app ' + a.short
                    })

        # Categories.
        cats = Category.objects
        cats = cats.filter(Q(application=request.APP.id) |
                           Q(type=amo.ADDON_SEARCH))
        if cat == 'themes':
            cats = cats.filter(type=amo.ADDON_PERSONA)
        else:
            cats = cats.exclude(type=amo.ADDON_PERSONA)

        for c in cats:
            if not c.name:
                continue
            name_ = unicode(c.name).lower()
            word_matches = [w for w in q_.split() if name_ in w]
            if q_ in name_ or word_matches:
                results.append({
                    'id': c.id,
                    'name': unicode(c.name),
                    'url': c.get_url_path(),
                    'cls': 'cat'
                })

        results += suggester.items

    return results
dataset/ETHPy150Open mozilla/addons-server/src/olympia/search/views.py/_build_suggestions/original