Last active
December 12, 2015 06:59
-
-
Save spuriousdata/4733251 to your computer and use it in GitHub Desktop.
monkeypatch pysolr to allow custom requesthandler
This file contains 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
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