__init__.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Flask-WhooshAlchemy3 作者: blakev 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号