Ejemplo n.º 1
0
def _fetch_facet_results(request):
    s = DCSolrSearch(request)
    facet_params = {
        'facet_mincount': 1,
    }
    facet_res = s.facets(fq=['type:duchemin_analysis'], **facet_params)
    facets = facet_res.facet_counts['facet_fields']
    # filtered_facets = dict([(k, v) for k, v in facets.iteritems() if k in settings.DISPLAY_FACETS])

    filtered_facets = []
    for k, v in facets.iteritems():
        this_facet = []
        if k not in settings.DISPLAY_FACETS.keys():
            continue
        for facet_value, num in v.iteritems():
            if k == "book_id_title":
                facet_info = facet_value.split("_")
                this_facet.append([facet_info[1], settings.DISPLAY_FACETS[k][0], facet_info[0]])
            else:
                this_facet.append([facet_value, settings.DISPLAY_FACETS[k][0]])

        this_facet.sort()
        filtered_facets.append([settings.DISPLAY_FACETS[k][1], this_facet])

    filtered_facets.sort()

    print filtered_facets

    data = {
        'facet_results': filtered_facets
    }
    return render(request, 'search/facets.html', data)
Ejemplo n.º 2
0
def _fetch_element_results(request):
    s = DCSolrSearch(request)
    el_res = s.search(fq=['type:duchemin_analysis'], sort=['piece_id asc', 'phrase_number asc', 'start_measure asc'])

    if el_res.count == 0:
        return render(request, 'search/no_results.html')

    try:
        epage = int(request.GET.get('epage', '1'))
    except ValueError:
        epage = 1

    try:
        element_results = el_res.page(epage)
    except (EmptyPage, InvalidPage):
        element_results = el_res.page(el_res.num_pages)
    element_results.pager_id = 'elements'

    data = {
        'element_results': element_results
    }
    return render(request, 'search/element_result_list.html', data)
Ejemplo n.º 3
0
def _fetch_work_results(request):
    s = DCSolrSearch(request)
    work_res = s.group_search(['title'], fq=['type:(duchemin_analysis OR duchemin_piece)'])

    if work_res.count == 0:
        return render(request, 'search/no_results.html')

    try:
        wpage = int(request.GET.get('wpage', '1'))
    except ValueError:
        wpage = 1

    try:
        work_results = work_res.page(wpage)
    except (EmptyPage, InvalidPage):
        work_results = work_res.page(work_res.num_pages)
    work_results.pager_id = 'works'

    is_logged_in = False
    if request.user.is_authenticated():
        is_logged_in = True
        profile = request.user.profile
        favourite_pieces = [f[0] for f in profile.favourited_piece.all().values_list('piece_id')]
        print favourite_pieces
        if favourite_pieces:
            for piece in work_results.object_list:
                if piece.piece_id in favourite_pieces:
                    piece.is_favourite = True
                else:
                    piece.is_favourite = False

    data = {
        'work_results': work_results,
        'is_logged_in': is_logged_in
    }
    return render(request, 'search/work_result_list.html', data)
Ejemplo n.º 4
0
def _empty_search(request):
    s = DCSolrSearch(request)
    ret = s.facets(fq=['duchemin_analysis'], rows=0)

    facets = ret.facet_counts['facet_fields']
    cadence_alter = sorted(facets['cadence_alter'])
    book_title = sorted(facets['book_id_title'])
    cadence_final_tone = sorted(facets['cadence_final_tone'])
    cadence_kind = sorted(facets['cadence_kind'])
    composer = sorted(facets['composer'])
    contributor = sorted(facets['contributor'])
    is_cadence = sorted(facets['is_cadence'])
    repeat_kind = sorted(facets['repeat_kind'])
    text_treatment = sorted(facets['text_treatment'])

    book_info = sorted([tuple(book.split("_")) for book in book_title])

    cad_voice_cantz = [__construct_voice_facet(v, 'cadence_role_cantz', hidden=False) for v in VOICE_NAMES]
    cad_voice_tenz = [__construct_voice_facet(v, 'cadence_role_tenz') for v in VOICE_NAMES]

    intpatt_up6_voice = [__construct_voice_facet(v, 'intpatt_p6_up', hidden=False) for v in VOICE_NAMES]
    intpatt_lo6_voice = [__construct_voice_facet(v, 'intpatt_p6_lo') for v in VOICE_NAMES]

    intpatt_up3_voice = [__construct_voice_facet(v, 'intpatt_p3_up', hidden=False) for v in VOICE_NAMES]
    intpatt_lo3_voice = [__construct_voice_facet(v, 'intpatt_p3_lo') for v in VOICE_NAMES]

    intpatt_up53_voice = [__construct_voice_facet(v, 'intpatt_53_up', hidden=False) for v in VOICE_NAMES]
    intpatt_lo53_voice = [__construct_voice_facet(v, 'intpatt_53_lo') for v in VOICE_NAMES]

    prestype_nonim_up1 = [__construct_voice_facet(v, 'prestype_nim_up1', hidden=False) for v in VOICE_NAMES]
    prestype_nonim_lo1 = [__construct_voice_facet(v, 'prestype_nim_lo1') for v in VOICE_NAMES]
    prestype_nonim_up2 = [__construct_voice_facet(v, 'prestype_nim_up2') for v in VOICE_NAMES]
    prestype_nonim_lo2 = [__construct_voice_facet(v, 'prestype_nim_lo2') for v in VOICE_NAMES]

    prestype_free_dux = [__construct_voice_facet(v, 'prestype_free_dux', hidden=False) for v in VOICE_NAMES]
    prestype_free_comes = [__construct_voice_facet(v, 'prestype_free_comes') for v in VOICE_NAMES]

    prestype_imduet_dux1 = [__construct_voice_facet(v, 'prestype_imduet_dux1', hidden=False) for v in VOICE_NAMES]
    prestype_imduet_comes1 = [__construct_voice_facet(v, 'prestype_imduet_comes1') for v in VOICE_NAMES]
    prestype_imduet_dux2 = [__construct_voice_facet(v, 'prestype_imduet_dux2') for v in VOICE_NAMES]
    prestype_imduet_comes2 = [__construct_voice_facet(v, 'prestype_imduet_comes2') for v in VOICE_NAMES]

    prestype_entry_dux1 = [__construct_voice_facet(v, 'prestype_entry_p_dux1', hidden=False) for v in VOICE_NAMES]
    prestype_entry_comes1 = [__construct_voice_facet(v, 'prestype_entry_p_comes1') for v in VOICE_NAMES]
    prestype_entry_dux2 = [__construct_voice_facet(v, 'prestype_entry_p_dux2') for v in VOICE_NAMES]
    prestype_entry_comes2 = [__construct_voice_facet(v, 'prestype_entry_p_comes2') for v in VOICE_NAMES]

    prestype_entry_t_dux1 = [__construct_voice_facet(v, 'prestype_entry_t_dux1', hidden=False) for v in VOICE_NAMES]
    prestype_entry_t_comes1 = [__construct_voice_facet(v, 'prestype_entry_t_comes1') for v in VOICE_NAMES]
    prestype_entry_t_dux2 = [__construct_voice_facet(v, 'prestype_entry_t_dux2') for v in VOICE_NAMES]
    prestype_entry_t_comes2 = [__construct_voice_facet(v, 'prestype_entry_t_comes2') for v in VOICE_NAMES]

    prestype_entry_s_dux1 = [__construct_voice_facet(v, 'prestype_entry_s_dux1', hidden=False) for v in VOICE_NAMES]
    prestype_entry_s_comes1 = [__construct_voice_facet(v, 'prestype_entry_s_comes1') for v in VOICE_NAMES]
    prestype_entry_s_dux2 = [__construct_voice_facet(v, 'prestype_entry_s_dux2') for v in VOICE_NAMES]
    prestype_entry_s_comes2 = [__construct_voice_facet(v, 'prestype_entry_s_comes2') for v in VOICE_NAMES]

    data = {
        'book_info': book_info,
        'cadence_alters': cadence_alter,
        'cadence_final_tones': cadence_final_tone,
        'cadence_kinds': cadence_kind,
        'composers': composer,
        'contributors': contributor,
        'is_cadences': is_cadence,
        'repeat_kinds': repeat_kind,
        'text_treatments': text_treatment,
        'cad_voice_cantz': cad_voice_cantz,
        'cad_voice_tenz': cad_voice_tenz,
        'intpatt_up6_voice': intpatt_up6_voice,
        'intpatt_lo6_voice': intpatt_lo6_voice,
        'intpatt_up3_voice': intpatt_up3_voice,
        'intpatt_lo3_voice': intpatt_lo3_voice,
        'intpatt_up53_voice': intpatt_up53_voice,
        'intpatt_lo53_voice': intpatt_lo53_voice,
        'prestype_nonim_up1': prestype_nonim_up1,
        'prestype_nonim_lo1': prestype_nonim_lo1,
        'prestype_nonim_up2': prestype_nonim_up2,
        'prestype_nonim_lo2': prestype_nonim_lo2,
        'prestype_free_dux': prestype_free_dux,
        'prestype_free_comes': prestype_free_comes,
        'prestype_imduet_dux1': prestype_imduet_dux1,
        'prestype_imduet_comes1': prestype_imduet_comes1,
        'prestype_imduet_dux2': prestype_imduet_dux2,
        'prestype_imduet_comes2': prestype_imduet_comes2,
        'prestype_entry_dux1': prestype_entry_dux1,
        'prestype_entry_comes1': prestype_entry_comes1,
        'prestype_entry_dux2': prestype_entry_dux2,
        'prestype_entry_comes2': prestype_entry_comes2,
        'prestype_entry_t_dux1': prestype_entry_t_dux1,
        'prestype_entry_t_comes1': prestype_entry_t_comes1,
        'prestype_entry_t_dux2': prestype_entry_t_dux2,
        'prestype_entry_t_comes2': prestype_entry_t_comes2,
        'prestype_entry_s_dux1': prestype_entry_s_dux1,
        'prestype_entry_s_comes1': prestype_entry_s_comes1,
        'prestype_entry_s_dux2': prestype_entry_s_dux2,
        'prestype_entry_s_comes2': prestype_entry_s_comes2,
    }
    return render(request, 'search/search.html', data)