Skip to content

Instantly share code, notes, and snippets.

@aholachek
Created September 23, 2014 14:54
Show Gist options
  • Save aholachek/dcb0400c7b72078f6671 to your computer and use it in GitHub Desktop.
Save aholachek/dcb0400c7b72078f6671 to your computer and use it in GitHub Desktop.
Querying solr using requests library
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