Skip to content

Commit

Permalink
Prevent Whoosh from erroring if the end_offset is less than or eq…
Browse files Browse the repository at this point in the history
…ual to 0. Thanks to zifot for the report!
  • Loading branch information
toastdriven committed Oct 27, 2010
1 parent e0dc369 commit eb978f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions haystack/backends/whoosh_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
'hits': 0,
}

# Prevent against Whoosh throwing an error. Requires an end_offset
# greater than 0.
if not end_offset is None and end_offset <= 0:
end_offset = 1

raw_results = searcher.search(parsed_query, limit=end_offset, sortedby=sort_by, reverse=reverse)

# Handle the case where the results have been narrowed.
Expand Down
4 changes: 4 additions & 0 deletions tests/whoosh_tests/tests/whoosh_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ def test_slicing(self):
self.assertEqual([result.pk for result in page_1['results']], [u'%s' % i for i in xrange(1, 21)])
self.assertEqual(len(page_2['results']), 3)
self.assertEqual([result.pk for result in page_2['results']], [u'21', u'22', u'23'])

# This used to throw an error.
page_0 = self.sb.search(u'*', start_offset=0, end_offset=0)
self.assertEqual(len(page_0['results']), 1)

def test_scoring(self):
self.sb.update(self.smmi, self.sample_objs)
Expand Down

0 comments on commit eb978f2

Please sign in to comment.