Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions flask_whooshalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ def __iter__(self):
if self._whoosh_results is None or self._order_by is not False:
return _iter

super_rows = list(_iter) # Correcting Pagination BUG

ordered = []

for row in _iter:
# for row in _iter: # Correcting Pagination BUG
for row in super_rows: # Correcting Pagination BUG
# we have to convert the primary-key, as stored in the SQL database
# into a string because the key is stored as an `ID` in whoosh.
# The ID field is string only; plus, this allows for uuid pk's.
str_pk = str(getattr(row, self._pk))
heapq.heappush(
ordered, (self._whoosh_results[str_pk], row))

if hasattr(row, self._pk): # Correcting Pagination BUG
str_pk = str(getattr(row, self._pk))
heapq.heappush(
ordered, (self._whoosh_results[str_pk], row))
else: # Correcting Pagination BUG
# PK column not found in result row # Correcting Pagination BUG
return iter(super_rows) # Correcting Pagination BUG

def inner():
while ordered:
yield heapq.heappop(ordered)[1]
Expand Down