Skip to content

Instantly share code, notes, and snippets.

@spuriousdata
Last active December 12, 2015 06:59
Show Gist options
  • Save spuriousdata/4733251 to your computer and use it in GitHub Desktop.
Save spuriousdata/4733251 to your computer and use it in GitHub Desktop.
monkeypatch pysolr to allow custom requesthandler
import pysolr
def monkeypatch_pysolr(handler='edismax', solr=None):
if solr is None:
solr = pysolr.Solr('http://localhost:8080/solr')
def better_select(params):
self = solr
params['wt'] = 'json'
params_encoded = pysolr.safe_urlencode(params, True)
if len(params_encoded) < 1024:
path = '%s/?%s' % (handler, params_encoded)
return self._send_request('get', path)
else:
path = '%s/' % handler
headers = {'Content-type': 'application/x-www-form-urlencoded; charset=utf-8',}
return self._send_request('post', path, body=params_encoded, headers=headers)
solr._select = better_select
return solr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment