Skip to content

Commit

Permalink
Merge pull request django-haystack#142 from yspanchal/master
Browse files Browse the repository at this point in the history
Add support for cursormark pagination
  • Loading branch information
acdha committed Sep 24, 2015
2 parents a1de02b + a4dc27f commit 61c917e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pysolr.py
Expand Up @@ -221,7 +221,7 @@ class SolrError(Exception):
class Results(object):
def __init__(self, docs, hits, highlighting=None, facets=None,
spellcheck=None, stats=None, qtime=None, debug=None,
grouped=None):
grouped=None, nextCursorMark=None):
self.docs = docs
self.hits = hits
self.highlighting = highlighting or {}
Expand All @@ -231,6 +231,7 @@ def __init__(self, docs, hits, highlighting=None, facets=None,
self.qtime = qtime
self.debug = debug or {}
self.grouped = grouped or {}
self.nextCursorMark = nextCursorMark or None

def __len__(self):
return len(self.docs)
Expand Down Expand Up @@ -654,6 +655,9 @@ def search(self, q, **kwargs):
if result.get('grouped'):
result_kwargs['grouped'] = result['grouped']

if result.get('nextCursorMark'):
result_kwargs['nextCursorMark'] = result['nextCursorMark']

response = result.get('response') or {}
numFound = response.get('numFound', 0)
self.log.debug("Found '%s' search results.", numFound)
Expand Down
7 changes: 7 additions & 0 deletions tests/client.py
Expand Up @@ -206,6 +206,13 @@ def test__select(self):
self.assertEqual(resp_data['response']['numFound'], 0)
self.assertEqual(len(resp_data['responseHeader']['params']['q']), 3 * 1024)

# Test Deep Pagination CursorMark
resp_body = self.solr._select({'q': '*', 'cursorMark':'*', 'sort':'id desc', 'start':0, 'rows': 2})
resp_data = json.loads(resp_body)
self.assertEqual(len(resp_data['response']['docs']), 2)
self.assertIn('nextCursorMark', resp_data)


def test__mlt(self):
resp_body = self.solr._mlt({'q': 'id:doc_1', 'mlt.fl': 'title'})
resp_data = json.loads(resp_body)
Expand Down

0 comments on commit 61c917e

Please sign in to comment.