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)
def search(): query = request.args.get('query') limit = int(request.args.get('limit', 10)) offset = int(request.args.get('offset', 0)) result = Topic.search(query, offset=offset, limit=limit) topics = result.get('data') pagination = dict(limit=limit, offset=offset, total=Topic.count_search(query)) return jsonify( dict(data=[topic.json_data() for topic in topics], pagination=pagination))
def search(): query = request.args.get('query') limit = int(request.args.get('limit', 10)) offset = int(request.args.get('offset', 0)) result = Topic.search(query, offset=offset, limit=limit) topics = result.get('data') pagination = dict( limit=limit, offset=offset, total=Topic.count_search(query) ) return jsonify(dict( data=[topic.json_data() for topic in topics], pagination=pagination ))