Esempio n. 1
0
    def test_sidebar_facets_show_number_of_results_per_facet(self):
        '''Test the underlying functionality behind the following interaction:

           Search for "Chicago", and then click on "Jazz" in the sidebar facets
           to filter that serach to finding aids tagged with the "Jazz" topic.

           The initial search should contain a greater number of records than
           the filtered search, and the sidebar facet should be able to
           correctly display the number of results that will result from a
           filtered search.'''

        s = get_search(*self.production_server_args +
                       ('Chicago', 'relevance', 0, 25, 10, [], ''))
        initial_total = s['total']

        collection = filtered_total = None
        for t in s['more-topics']:
            if t[1] == 'Jazz':
                collection, _, filtered_total = t
        self.assertIsNotNone(collection)
        self.assertGreater(initial_total, filtered_total)

        s = get_search(*self.production_server_args +
                       ('Chicago', 'relevance', 0, 25, 10, [collection], ''))
        self.assertEqual(filtered_total, s['total'])
Esempio n. 2
0
    def test_paging_with_single_search_result(self):
        '''Use a search for a single result to confirm that paging works
           correctly.'''

        s1 = get_search(*self.production_server_args +
                        ('Oyebemi', 'relevance', 0, 1, 1, [], ''))
        s2 = get_search(*self.production_server_args +
                        ('Oyebemi', 'relevance', 1, 1, 1, [], ''))
        self.assertEqual(len(s1['results']), 1)
        self.assertEqual(len(s2['results']), 0)
Esempio n. 3
0
    def test_search_result_sorting(self):
        s1 = get_search(*self.production_server_args +
                        ('Oneida', 'alpha', 0, 25, 10, [], ''))
        orig_alpha_sorted_titles = [t['title'] for t in s1['results']]
        manually_alpha_sorted_titles = sorted(orig_alpha_sorted_titles)
        self.assertEqual(orig_alpha_sorted_titles,
                         manually_alpha_sorted_titles)

        s2 = get_search(*self.production_server_args +
                        ('Oneida', 'alpha-dsc', 0, 25, 10, [], ''))
        orig_alpha_dsc_sorted_titles = [t['title'] for t in s2['results']]
        manually_alpha_dsc_sorted_titles = sorted(orig_alpha_dsc_sorted_titles,
                                                  reverse=True)
        self.assertEqual(orig_alpha_dsc_sorted_titles,
                         manually_alpha_dsc_sorted_titles)
Esempio n. 4
0
    def test_proximity_search(self):
        '''A search for "bronzeville video" (without quotes) should return the
           "VHS video collection" finding aid near the top of results.'''

        s = get_search(*self.production_server_args +
                       ('bronzeville video', 'alpha-dsc', 0, 25, 10, [], ''))
        uris = [r['uri'] for r in s['results']]
        self.assertTrue('BMRC.BRONZEVILLE.VHS.xml' in uris)
Esempio n. 5
0
def facet_view_all():
    a = request.args.get('a', default='', type=str)
    collections_active = request.args.getlist('f')
    fsort = request.args.get('fsort', default='relevance', type=str)
    q = request.args.get('q', default='', type=str)
    sort = request.args.get('sort', default='relevance', type=str)

    assert sort in ('alpha', 'alpha-dsc', 'relevance', 'shuffle')

    search_results = {}

    if collections_active:
        search_results['collections-active'] = []
        for c in collections_active:
            search_results['collections-active'].append(
                [c, unquote_plus(c.split('/')[4]), 0])

    facet_name = a.replace('https://bmrc.lib.uchicago.edu/', '').split('/')[0]
    assert facet_name in ('archives', 'decades', 'organizations', 'people',
                          'places', 'topics')

    title = facet_name.capitalize()

    search_results = get_search(*server_args +
                                (q, sort, 0, 1, -1, collections_active, ''))

    # To simplify the template, append a fourth element to each list: True if
    # the facet is currently active, false if not.
    out = []
    for f in search_results['active-' + facet_name]:
        out.append(f + [True])
    for f in search_results['more-' + facet_name]:
        out.append(f + [False])

    if fsort == 'relevance':
        out.sort(key=lambda i: i[2], reverse=True)
    elif fsort == 'alpha':
        out.sort(key=lambda i: re.sub('^The ', '', i[1]).lower())
    elif fsort == 'alpha-dsc':
        out.sort(key=lambda i: re.sub('^The ', '', i[1]).lower(), reverse=True)
    elif fsort == 'shuffle':
        random.shuffle(out)

    return render_template('facet_view_all.html',
                           a=a,
                           collection=out,
                           collection_active=collections_active,
                           fsort=fsort,
                           q=q,
                           search_results=search_results,
                           title=title)
Esempio n. 6
0
def search():
    b = request.args.get('b', default='', type=str)
    collections = request.args.getlist('f')
    page = request.args.get('page', default=1, type=int)
    q = request.args.get('q', default='', type=str)
    sort = request.args.get('sort', default='', type=str)

    # with a page length of 3, this is:
    # (0, 3), (3, 6), (6, 9)...

    start = (page - 1) * app.config['PAGE_LENGTH']
    stop = start + app.config['PAGE_LENGTH']

    if sort == '':
        if q == '':
            sort = 'alpha'
        else:
            sort = 'relevance'

    search_results = get_search(
        *server_args +
        (q, sort, start, app.config['PAGE_LENGTH'],
         app.config['SIDEBAR_VIEW_MORE_FACET_COUNT'], collections, b))

    # redirect to the view if there is a single result.
    # if search_results['total'] == 1:
    #     return redirect(
    #         '/view/?{}'.format(
    #             urllib.parse.urlencode({
    #                 'id': search_results['results'][0]['uri']
    #             })
    #         )
    #     )

    total_pages = math.ceil(search_results['total'] /
                            app.config['PAGE_LENGTH'])
    min_page_link, max_page_link = get_min_max_page_links(page, total_pages)

    if q:
        title = 'Portal Search - {}'.format(q)
    else:
        title = 'Portal Search'

    # if this search includes an archive facet, get the logo, short title and
    # html for archive contact info.
    archivebox_address = archivebox_link = archivebox_logo = name = ''
    c = [
        c for c in collections
        if c.startswith('https://bmrc.lib.uchicago.edu/archives/')
    ]
    try:
        s = urllib.parse.unquote_plus(c[0].replace(
            'https://bmrc.lib.uchicago.edu/archives/', ''))
        a = [a for a in app.config['ARCHIVES'] if a['name'] == s]
        archivebox_address = a[0]['archivebox_address']
        archivebox_link = a[0]['archivebox_link']
        archivebox_logo = a[0]['archivebox_logo']
        name = a[0]['name']
    except IndexError:
        pass

    return render_template('search.html',
                           archivebox_address=archivebox_address,
                           archivebox_link=archivebox_link,
                           archivebox_logo=archivebox_logo,
                           breadcrumbs=[
                               ('https://bmrc.lib.uchicago.edu/',
                                'Black Metropolis Research Consortium'),
                               ('/', 'Collections Portal')
                           ],
                           max_page_link=max_page_link,
                           min_page_link=min_page_link,
                           page=page,
                           page_length=app.config['PAGE_LENGTH'],
                           search_results=search_results,
                           sidebar_view_less_facet_count=app.
                           config['SIDEBAR_VIEW_LESS_FACET_COUNT'],
                           sidebar_view_more_facet_count=app.
                           config['SIDEBAR_VIEW_MORE_FACET_COUNT'],
                           name=name,
                           sort=sort,
                           start=start,
                           title=title,
                           total_pages=total_pages)
Esempio n. 7
0
 def s(q):
     return get_search(*self.production_server_args +
                       (q, 'relevance', 0, 25, 10, [], ''))