本文整理汇总了Python中models.Article.search方法的典型用法代码示例。如果您正苦于以下问题:Python Article.search方法的具体用法?Python Article.search怎么用?Python Article.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.search方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import search [as 别名]
def search():
query = request.args.get('query', '')
query = query.strip()
if len(query) == 0:
return redirect('/')
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 10))
# search articles
result = Article.search(query, offset=offset, limit=limit)
articles = result.get('data')
articles = [article.json_data() for article in articles]
context = {
'search': query,
'offset': offset,
'limit': limit,
'js_module': 'search',
'style': 'search',
'articles': articles,
'total_article': result['raw']['total_found'],
'total_topic': Topic.count_search(query)
}
return render_template('site/search.html', **context)
示例2: search
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import search [as 别名]
def search():
query = request.args.get('query')
limit = int(request.args.get('limit', 10))
offset = int(request.args.get('offset', 0))
result = Article.search(query, offset=offset, limit=limit)
articles = result.get('data')
pagination = dict(
limit=limit,
offset=offset,
total=Article.count_search(query)
)
return jsonify(dict(
data=[article.json_data() for article in articles],
pagination=pagination
))