Beispiel #1
0
def results(request):
    term = request.GET.get("q")
    ret = {}
    error = False
    if term:
        try:
            suggestions = search.autocomplete(term)
            for l in suggestions:
                doc = {
                    'label': l['title_t'],
                    'id': l['object_id_i'],
                }
                if l['type_s'] not in ret:
                    ret[l['type_s']] = []

                if 'mbid_s' not in l:
                    l['mbid_s'] = ''
                if 'composer_s' in l:
                    doc['composer'] = l['composer_s']
                if 'artists_s' in l:
                    doc['artists'] = l['artists_s']

                doc['mbid'] = l['mbid_s']
                ret[l['type_s']].append(doc)
        except pysolr.SolrError:
            error = True
    return render(request, "makam/results.html", {
        'results': ret,
        'error': error
    })
Beispiel #2
0
def searchcomplete(request):
    term = request.GET.get("term")
    ret = []
    error = False
    if term:
        try:
            suggestions = search.autocomplete(term)
            ret = []
            for l in suggestions:
                label = l['title_t']
                if 'composer_s' in l:
                    label += ' - ' + l['composer_s']
                if 'artists_s' in l:
                    artists = l['artists_s']
                    if len(artists) > 40:
                        artists = artists[:40] + "..."
                    label += ' - ' + artists
                if 'mbid_s' not in l:
                    l['mbid_s'] = ''

                ret.append({
                    "id": l['object_id_i'],
                    "label": label,
                    "category": l['type_s'],
                    "mbid": l['mbid_s']
                })
        except pysolr.SolrError:
            error = True
    return HttpResponse(json.dumps(ret), content_type="application/json")
Beispiel #3
0
def results(request):
    term = request.GET.get("q")
    ret = {}
    error = False
    if term:
        try:
            suggestions = search.autocomplete(term)
            for l in suggestions:
                doc = {'label': l['title_t'], 'id': l['object_id_i'],}
                if l['type_s'] not in ret:
                    ret[l['type_s']] = []

                if 'mbid_s' not in l:
                    l['mbid_s'] = ''
                if 'composer_s' in l:
                    doc['composer'] = l['composer_s']
                if 'artists_s' in l:
                    doc['artists'] = l['artists_s']

                doc['mbid'] = l['mbid_s']
                ret[l['type_s']].append(doc)
        except pysolr.SolrError:
            error = True
    return render(request, "makam/results.html", {'results': ret, 'error': error})
Beispiel #4
0
def searchcomplete(request):
    term = request.GET.get("term")
    ret = []
    error = False
    if term:
        try:
            suggestions = search.autocomplete(term)
            ret = []
            for l in suggestions:
                label = l['title_t']
                if 'composer_s' in l:
                    label += ' - ' +l['composer_s']
                if 'artists_s' in l:
                    artists = l['artists_s']
                    if len(artists) > 40:
                        artists = artists[:40] + "..."
                    label += ' - ' + artists
                if 'mbid_s' not in l:
                    l['mbid_s'] = ''

                ret.append({"id": l['object_id_i'], "label": label, "category": l['type_s'], "mbid": l['mbid_s']})
        except pysolr.SolrError:
            error = True
    return HttpResponse(json.dumps(ret), content_type="application/json")