Created
September 23, 2014 14:54
-
-
Save aholachek/dcb0400c7b72078f6671 to your computer and use it in GitHub Desktop.
Querying solr using requests library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOLR_PATH = 'http://localhost:9000/solr/select/' | |
def query_solr(q = '', start = 0, rows = 200, fl = 'bibcode,title,recid,citation_count,year,property', sort = "date desc"): | |
d = {'q' : q, | |
'sort': sort, | |
'fl' : fl, | |
'start' : start, | |
'rows' : rows, | |
'wt': 'json', | |
'hl': 'true', | |
'hl.fl':'abstract,ack,body', | |
} | |
response = requests.get(SOLR_PATH , params = d) | |
if response.status_code == 200: | |
results = response.json() | |
return results | |
sys.stderr.write('There was a network problem: {0}\n'.format(response)) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment