handler.py 文件源码

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

项目:Ushio 作者: Hanaasagi 项目源码 文件源码
def get(self):
        keyword = self.get_query_argument('keyword', '')
        if not keyword:
            self.custom_error('???????')
        pattern = u'.*{}.*'.format(re.escape(keyword))
        limit = 20
        page = int(self.get_query_argument('page', default=1))
        page = 1 if page <= 0 else page

        # ????title????
        # ?????? elstiasearch ????
        cursor = self.db.topic.find({
            'title': {'$regex': pattern, '$options': 'i'}
        })
        total = yield cursor.count()
        cursor.sort([('time', -1)]).limit(
            limit).skip((page - 1) * limit)
        topics = yield cursor.to_list(length=limit)
        self.render('search/template/search.html',
                    topics=topics, total=total, page=page, keyword=keyword)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号