Beispiel #1
0
    def GET(self):
        i = web.input(q="", limit=5)
        i.limit = safeint(i.limit, 5)

        solr = get_solr()

        q = solr.escape(i.q).strip()
        if is_work_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/works/%s"' % q.upper()
        else:
            solr_q = 'title:"%s"^2 OR title:(%s*)' % (q, q)

        params = {
            'q_op': 'AND',
            'sort': 'edition_count desc',
            'rows': i.limit,
            'fq': 'type:work',
            # limit the fields returned for better performance
            'fl': 'key,title,first_publish_year,author_name,edition_count'
        }

        data = solr.select(solr_q, **params)
        docs = data['docs']

        for d in docs:
            # Required by the frontend
            d['name'] = d['title']
        return to_json(docs)
Beispiel #2
0
    def GET(self):
        i = web.input(q="", limit=5)
        i.limit = safeint(i.limit, 5)

        solr = get_solr()

        q = solr.escape(i.q).strip()
        if is_work_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/works/%s"' % q.upper()
        else:
            solr_q = 'title:"%s"^2 OR title:(%s*)' % (q, q)

        params = {
            'q_op': 'AND',
            'sort': 'edition_count desc',
            'rows': i.limit,
            'fq': 'type:work',
            # limit the fields returned for better performance
            'fl': 'key,title,subtitle,cover_i,first_publish_year,author_name,edition_count'
        }

        data = solr.select(solr_q, **params)
        # exclude fake works that actually have an edition key
        docs = [d for d in data['docs'] if d['key'][-1] == 'W']

        for d in docs:
            # Required by the frontend
            d['name'] = d['key'].split('/')[-1]
            d['full_title'] = d['title']
            if 'subtitle' in d:
                d['full_title'] += ": " + d['subtitle']
        return to_json(docs)
Beispiel #3
0
    def GET(self):
        i = web.input(q="", limit=5)
        i.limit = safeint(i.limit, 5)

        solr = get_solr()

        q = solr.escape(i.q).strip()
        if is_work_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/works/%s"' % q.upper()
        else:
            solr_q = 'title:"%s"^2 OR title:(%s*)' % (q, q)

        params = {
            'q_op': 'AND',
            'sort': 'edition_count desc',
            'rows': i.limit,
            'fq': 'type:work',
            # limit the fields returned for better performance
            'fl': 'key,title,subtitle,cover_i,first_publish_year,author_name,edition_count'
        }

        data = solr.select(solr_q, **params)
        # exclude fake works that actually have an edition key
        docs = [d for d in data['docs'] if d['key'][-1] == 'W']

        for d in docs:
            # Required by the frontend
            d['name'] = d['title']
            d['full_title'] = d['title']
            if 'subtitle' in d:
                d['full_title'] += ": " + d['subtitle']
        return to_json(docs)
Beispiel #4
0
    def GET(self):
        i = web.input(q="", limit=5)
        i.limit = safeint(i.limit, 5)

        solr = get_solr()

        q = solr.escape(i.q).strip()
        query_is_key = is_work_olid(q.upper())
        if query_is_key:
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/works/%s"' % q.upper()
        else:
            solr_q = f'title:"{q}"^2 OR title:({q}*)'

        params = {
            'q_op':
            'AND',
            'sort':
            'edition_count desc',
            'rows':
            i.limit,
            'fq':
            'type:work',
            # limit the fields returned for better performance
            'fl':
            'key,title,subtitle,cover_i,first_publish_year,author_name,edition_count',
        }

        data = solr.select(solr_q, **params)
        # exclude fake works that actually have an edition key
        docs = [d for d in data['docs'] if d['key'][-1] == 'W']

        if query_is_key and not docs:
            # Grumble! Work not in solr yet. Create a dummy.
            key = '/works/%s' % q.upper()
            work = web.ctx.site.get(key)
            if work:
                docs = [work.as_fake_solr_record()]

        for d in docs:
            # Required by the frontend
            d['name'] = d['key'].split('/')[-1]
            d['full_title'] = d['title']
            if 'subtitle' in d:
                d['full_title'] += ": " + d['subtitle']

        return to_json(docs)