Skip to content
Browse files

Allowed for connections to solr instances that don't live at /solr.

git-svn-id: https://pysolr.googlecode.com/svn/trunk@7 13ae9d4a-4d43-0410-997b-81b7443f7ec1
  • Loading branch information...
1 parent 57baa10 commit 46849b12547f4244de7436d0d90a8829feea54e8 @jkocherhans committed Jan 24, 2008
Showing with 13 additions and 8 deletions.
  1. +13 −8 pysolr.py
View
21 pysolr.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""
-All we need to create a Solr connection is an address.
+All we need to create a Solr connection is a url.
->>> conn = Solr(host='127.0.0.1')
+>>> conn = Solr('http://127.0.0.1:8983/solr/')
First, completely clear the index.
@@ -102,6 +102,7 @@
from httplib import HTTPConnection
from urllib import urlencode
+from urlparse import urlsplit
from datetime import datetime, date
from time import strptime, strftime
try:
@@ -127,25 +128,29 @@ def __iter__(self):
return iter(self.docs)
class Solr(object):
- def __init__(self, host, port=8983):
- self.host = host
- self.port = port
+ def __init__(self, url):
+ self.url = url
+ self.o = urlsplit(url)
+ self.host = self.o.hostname
+ self.port = self.o.port
+ self.path = self.o.path.rstrip('/')
def _select(self, params):
# encode the query as utf-8 so urlencode can handle it
params['q'] = params['q'].encode('utf-8')
+ path = '%s/select/?%s' % (self.path, urlencode(params))
conn = HTTPConnection(self.host, self.port)
- url = '/solr/select/?%s' % urlencode(params)
- conn.request('GET', url)
+ conn.request('GET', path)
return conn.getresponse()
def _update(self, message):
"""
Posts the given xml message to http://<host>:<port>/solr/update and
returns the result.
"""
+ path = '%s/update/' % self.path
conn = HTTPConnection(self.host, self.port)
- conn.request('POST', '/solr/update/', message, {'Content-type': 'text/xml'})
+ conn.request('POST', path, message, {'Content-type': 'text/xml'})
return conn.getresponse()
def _extract_error(self, response):

0 comments on commit 46849b1

Please sign in to comment.
Something went wrong with that request. Please try again.