Exemplo n.º 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()
        solr_q = ''
        if is_author_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/authors/%s"' % q.upper()
        else:
            prefix_q = q + "*"
            solr_q = 'name:(%s) OR alternate_names:(%s)' % (prefix_q, prefix_q)

        params = {
            'q_op': 'AND',
            'sort': 'work_count desc',
            'rows': i.limit,
            'fq': 'type:author'
        }

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

        for d in docs:
            if 'top_work' in d:
                d['works'] = [d.pop('top_work')]
            else:
                d['works'] = []
            d['subjects'] = d.pop('top_subjects', [])

        return to_json(docs)
Exemplo n.º 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()
        solr_q = ''
        if is_author_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/authors/%s"' % q.upper()
        else:
            prefix_q = q + "*"
            solr_q = 'name:(%s) OR alternate_names:(%s)' % (prefix_q, prefix_q)

        params = {
            'q_op': 'AND',
            'sort': 'work_count desc',
            'rows': i.limit,
            'fq': 'type:author'
        }

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

        for d in docs:
            if 'top_work' in d:
                d['works'] = [d.pop('top_work')]
            else:
                d['works'] = []
            d['subjects'] = d.pop('top_subjects', [])

        return to_json(docs)
Exemplo n.º 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()
        query_is_key = is_author_olid(q.upper())
        if query_is_key:
            # ensure uppercase; key is case sensitive in solr
            solr_q = 'key:"/authors/%s"' % q.upper()
        else:
            prefix_q = q + "*"
            solr_q = f'name:({prefix_q}) OR alternate_names:({prefix_q})'

        params = {
            'q_op': 'AND',
            'sort': 'work_count desc',
            'rows': i.limit,
            'fq': 'type:author',
        }

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

        if query_is_key and not docs:
            # Grumble! Must be a new author. Fetch from db, and build a "fake" solr resp
            key = '/authors/%s' % q.upper()
            author = web.ctx.site.get(key)
            if author:
                docs = [author.as_fake_solr_record()]

        for d in docs:
            if 'top_work' in d:
                d['works'] = [d.pop('top_work')]
            else:
                d['works'] = []
            d['subjects'] = d.pop('top_subjects', [])

        return to_json(docs)
Exemplo n.º 4
0
    def GET(self):
        i = web.input(q="", limit=5)
        i.limit = safeint(i.limit, 5)

        solr = get_authors_solr()

        q = solr.escape(i.q).strip()
        solr_q = ''
        if is_author_olid(q.upper()):
            # ensure uppercase; key is case sensitive in solr
            key_q = q.upper()
            if config.get('single_core_solr'):
                key_q = "/authors/" + key_q
            solr_q = 'key:"%s"' % key_q
        else:
            prefix_q = q + "*"
            solr_q = 'name:(%s) OR alternate_names:(%s)' % (prefix_q, prefix_q)

        params = {'q_op': 'AND', 'sort': 'work_count desc', 'rows': i.limit}

        if config.get('single_core_solr'):
            params['fq'] = 'type:author'
        data = solr.select(solr_q, **params)
        docs = data['docs']

        if not config.get('single_core_solr'):
            for d in docs:
                d.key = "/authors/" + d.key

        for d in docs:
            if 'top_work' in d:
                d['works'] = [d.pop('top_work')]
            else:
                d['works'] = []
            d['subjects'] = d.pop('top_subjects', [])

        return to_json(docs)