Skip to content

Commit

Permalink
Broke results out into a separate object with docs and hits attributes.
Browse files Browse the repository at this point in the history
git-svn-id: https://pysolr.googlecode.com/svn/trunk@5 13ae9d4a-4d43-0410-997b-81b7443f7ec1
  • Loading branch information
jkocherhans committed Jan 17, 2008
1 parent f984d07 commit 8ea1712
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pysolr.py
Expand Up @@ -90,6 +90,11 @@
class SolrError(Exception):
pass

class Results(object):
def __init__(self, docs, hits):
self.docs = docs
self.hits = hits

class Solr(object):
def __init__(self, host, port=8983):
self.host = host
Expand Down Expand Up @@ -182,6 +187,7 @@ def search(self, q, sort=None, start=0, rows=20):
# TODO: make result retrieval lazy and allow custom result objects
et = ElementTree.parse(response)
result = et.find('result')
hits = int(result.get('numFound'))
docs = result.findall('doc')
results = []
for doc in docs:
Expand All @@ -191,7 +197,7 @@ def search(self, q, sort=None, start=0, rows=20):
converter = getattr(self, converter_name)
result[element.get('name')] = converter(element.text)
results.append(result)
return results
return Results(results, hits)

def add(self, docs, commit=True):
"""Adds or updates documents. For now, docs is a list of dictionaies
Expand Down

0 comments on commit 8ea1712

Please sign in to comment.