@whooshee.register_model('title','content')
class PostModel(db.Model):
__tablename__ = 'post'
id = db.Column(db.Integer,primary_key=True,autoincrement=True)
title = db.Column(db.String(200),nullable=False)
content = db.Column(db.Text,nullable=False)
create_time = db.Column(db.DateTime,default=datetime.now)
read_count = db.Column(db.Integer,default=0)
board_id = db.Column(db.Integer,db.ForeignKey("board.id"))
author_id = db.Column(db.String(100),db.ForeignKey("front_user.id"),nullable=False
@bp.route('/search/')
def index_search():
q = request.args.get('q','').strip()
print(q)
if q == '':
flash('请输入关键字','warning')
return redirect(url_for('front.index'))
result = PostModel.query.whooshee_search(q).order_by(PostModel.create_time.desc()).all()
print(result)
return render_template('front/front_search.html',result=result)
代码如下 工厂函数已经注册whooshee 并且本地已经生成whooshee文件