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)
评论列表
文章目录