Beispiel #1
0
 def get_results(q, offset=0, limit=100):
     valid_fields = ['key', 'name', 'type', 'count']
     q = escape_colon(escape_bracket(q), valid_fields)
     solr_select = solr_subject_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=name,type,count&qt=standard&wt=json" % (
         web.urlquote(q), offset, limit)
     solr_select += '&sort=count+desc'
     return run_solr_search(solr_select)
Beispiel #2
0
    def get_results(self, q, offset=0, limit=100):
        if config.get('single_core_solr'):            
            valid_fields = ['key', 'name', 'subject_type', 'work_count']
        else:
            valid_fields = ['key', 'name', 'type', 'count']

        q = escape_colon(escape_bracket(q), valid_fields)
        params = {
            "q.op": "AND",
            "q": q,
            "start": offset,
            "rows": limit,
            "fl": ",".join(valid_fields),
            "qt": "standard",
            "wt": "json"
        }
        if config.get('single_core_solr'):
            params['fq'] = 'type:subject'
            params['sort'] = 'work_count desc'
        else:                
            params['sort'] = 'count desc'

        solr_select = solr_subject_select_url + "?" + urllib.urlencode(params)
        results = run_solr_search(solr_select)
        response = results['response']

        if config.get('single_core_solr'):
            response['docs'] = [self.process_doc(doc) for doc in response['docs']]

        return results
Beispiel #3
0
    def get_results(self, q, offset=0, limit=100):
        valid_fields = ['key', 'name', 'subject_type', 'work_count']
        q = escape_colon(escape_bracket(q), valid_fields)
        params = {
            "fq": "type:subject",
            "q.op": "AND",
            "q": q,
            "start": offset,
            "rows": limit,
            "fl": ",".join(valid_fields),
            "qt": "standard",
            "wt": "json",
            "sort": "work_count desc"
        }

        solr_select = solr_select_url + "?" + urllib.parse.urlencode(
            params, 'utf-8')
        results = run_solr_search(solr_select)
        response = results['response']

        for doc in response['docs']:
            doc['type'] = doc.get('subject_type', 'subject')
            doc['count'] = doc.get('work_count', 0)

        return results
Beispiel #4
0
    def get_results(self, q, offset=0, limit=100):
        if config.get('single_core_solr'):
            valid_fields = ['key', 'name', 'subject_type', 'work_count']
        else:
            valid_fields = ['key', 'name', 'type', 'count']

        q = escape_colon(escape_bracket(q), valid_fields)
        params = {
            "q.op": "AND",
            "q": q,
            "start": offset,
            "rows": limit,
            "fl": ",".join(valid_fields),
            "qt": "standard",
            "wt": "json"
        }
        if config.get('single_core_solr'):
            params['fq'] = 'type:subject'
            params['sort'] = 'work_count desc'
        else:
            params['sort'] = 'count desc'

        solr_select = solr_subject_select_url + "?" + urllib.urlencode(
            params, 'utf-8')
        results = run_solr_search(solr_select)
        response = results['response']

        if config.get('single_core_solr'):
            response['docs'] = [
                self.process_doc(doc) for doc in response['docs']
            ]

        return results
Beispiel #5
0
        def get_results(q, offset=0, limit=100):
            q = escape_bracket(q)
            solr_select = solr_edition_select_url + "?q.op=AND&q=%s&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)

            if config.get('single_core_solr'):
                solr_select += '&fq=type:edition'

            return run_solr_search(solr_select)
Beispiel #6
0
        def get_results(q, offset=0, limit=100):
            q = escape_bracket(q)
            solr_select = solr_edition_select_url + "?q.op=AND&q=%s&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)

            if config.get('single_core_solr'):
                solr_select += '&fq=type:edition'

            return run_solr_search(solr_select)
Beispiel #7
0
 def get_results(q, offset=0, limit=100):
     valid_fields = [
         'key', 'name', 'alternate_names', 'birth_date', 'death_date',
         'date', 'work_count'
     ]
     q = escape_colon(escape_bracket(q), valid_fields)
     solr_select = solr_author_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (
         web.urlquote(q), offset, limit)
     solr_select += '&sort=work_count+desc'
     return run_solr_search(solr_select)
Beispiel #8
0
    def get_results(self, q, offset=0, limit=100):
        valid_fields = ['key', 'name', 'alternate_names', 'birth_date', 'death_date', 'date', 'work_count']
        q = escape_colon(escape_bracket(q), valid_fields)

        solr_select = solr_select_url + "?fq=type:author&q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
        solr_select += '&sort=work_count+desc'
        d = run_solr_search(solr_select)

        docs = d.get('response', {}).get('docs', [])
        for doc in docs:
            # replace /authors/OL1A with OL1A
            # The template still expects the key to be in the old format
            doc['key'] = doc['key'].split("/")[-1]
        return d
Beispiel #9
0
    def get_results(self, q, offset=0, limit=100):
        valid_fields = ['key', 'name', 'alternate_names', 'birth_date', 'death_date', 'date', 'work_count']
        q = escape_colon(escape_bracket(q), valid_fields)

        solr_select = solr_select_url + "?fq=type:author&q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
        solr_select += '&sort=work_count+desc'
        d = run_solr_search(solr_select)

        docs = d.get('response', {}).get('docs', [])
        for doc in docs:
            # replace /authors/OL1A with OL1A
            # The template still expects the key to be in the old format
            doc['key'] = doc['key'].split("/")[-1]
        return d
Beispiel #10
0
    def get_results(self, q, offset=0, limit=100):
        valid_fields = [
            'key',
            'name',
            'alternate_names',
            'birth_date',
            'death_date',
            'date',
            'work_count',
        ]
        q = escape_colon(escape_bracket(q), valid_fields)
        q_has_fields = ':' in q.replace(r'\:', '') or '*' in q

        d = run_solr_search(
            solr_select_url,
            {
                'fq':
                'type:author',
                'q.op':
                'AND',
                'q':
                q,
                'start':
                offset,
                'rows':
                limit,
                'fl':
                '*',
                'qt':
                'standard',
                'sort':
                'work_count desc',
                'wt':
                'json',
                **({} if q_has_fields else {
                       'defType': 'dismax',
                       'qf': 'name alternate_names'
                   }),
            },
        )

        docs = d.get('response', {}).get('docs', [])
        for doc in docs:
            # replace /authors/OL1A with OL1A
            # The template still expects the key to be in the old format
            doc['key'] = doc['key'].split("/")[-1]
        return d
Beispiel #11
0
    def get_results(self, q, offset=0, limit=100):
        valid_fields = ['key', 'name', 'subject_type', 'work_count']
        q = escape_colon(escape_bracket(q), valid_fields)
        params = {
            "fq": "type:subject",
            "q.op": "AND",
            "q": q,
            "start": offset,
            "rows": limit,
            "fl": ",".join(valid_fields),
            "qt": "standard",
            "wt": "json",
            "sort": "work_count desc"
        }

        solr_select = solr_select_url + "?" + urllib.urlencode(params, 'utf-8')
        results = run_solr_search(solr_select)
        response = results['response']

        for doc in response['docs']:
            doc['type'] = doc.get('subject_type', 'subject')
            doc['count'] = doc.get('work_count', 0)

        return results
Beispiel #12
0
 def get_results(q, offset=0, limit=100):
     valid_fields = ['key', 'name', 'type', 'count']
     q = escape_colon(escape_bracket(q), valid_fields)
     solr_select = solr_subject_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=name,type,count&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
     solr_select += '&sort=count+desc'
     return run_solr_search(solr_select)
Beispiel #13
0
def escape_q(q):
    if re_inside_fields.match(q):
        return q
    return escape_bracket(q).replace(':', '\\:')
Beispiel #14
0
def escape_q(q):
    if re_inside_fields.match(q):
        return q
    return escape_bracket(q).replace(':', '\\:')
Beispiel #15
0
def test_escape_bracket():
    assert escape_bracket('test') == 'test'
    assert escape_bracket('this [is a] test') == 'this \\[is a\\] test'
    assert escape_bracket('aaa [10 TO 500] bbb') == 'aaa [10 TO 500] bbb'
Beispiel #16
0
 def get_results(q, offset=0, limit=100):
     q = escape_bracket(q)
     solr_select = solr_select_url + "?fq=type:edition&q.op=AND&q=%s&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (
         web.urlquote(q), offset, limit)
     return run_solr_search(solr_select)
Beispiel #17
0
 def get_results(self, q, offset=0, limit=100):
     valid_fields = ['key', 'name', 'alternate_names', 'birth_date', 'death_date', 'date', 'work_count']
     q = escape_colon(escape_bracket(q), valid_fields)
     solr_select = solr_author_select_url + "?q.op=AND&q=%s&fq=&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
     solr_select += '&sort=work_count+desc'
     return run_solr_search(solr_select)
Beispiel #18
0
 def get_results(q, offset=0, limit=100):
     q = escape_bracket(q)
     solr_select = solr_select_url + "?fq=type:edition&q.op=AND&q=%s&start=%d&rows=%d&fl=*&qt=standard&wt=json" % (web.urlquote(q), offset, limit)
     return run_solr_search(solr_select)
Beispiel #19
0
def test_escape_bracket():
    assert escape_bracket('test') == 'test'
    assert escape_bracket('this [is a] test') == 'this \\[is a\\] test'
    assert escape_bracket('aaa [10 TO 500] bbb') == 'aaa [10 TO 500] bbb'