def __iter__(self):
""" Sort the results by Whoosh rank; relevance. """
_iter = super(QueryProxy, self).__iter__()
if self._whoosh_results is None or self._order_by is not False:
return _iter
ordered = []
for row in _iter:
# 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))
def inner():
while ordered:
yield heapq.heappop(ordered)[1]
return inner()
评论列表
文章目录