使用whoosh_search查询时结果都是空怎么解决

调用whoosh_search方法查Post.query.whoosh_search('mus').all()
查到的结果:
E:Python27libsite-packagessqlalchemysqlelements.py:4230: SAWarning: Textual SQL expression 'null' should be explicitly declared as text('null') (this warning may be suppressed after 10 occurrences)
{"expr": util.ellipses_string(element)})
[]
我查的字段 searchable = ['title'];
打印结果:
SELECT posts.id AS posts_id, posts.title AS posts_title, posts.body AS posts_body, posts.created AS posts_created, posts.clicks AS posts_clicks, posts.author_id AS posts_author_id
FROM posts
WHERE null
where null 是什么怎么回事啊?
我数据库title里面确实有mus这个词的
还有问题就是下面这个search.db是什么意思,网上用flask_whooshalchemy的资料只有一篇
app.config['WHOOSH_BASE']=os.path.join(basedir, 'data.sqlite')
shell里面调用whoosh_index()函数是报错:
图片描述

阅读 5.8k
4 个回答

where null 是因为whoosh搜索时结果为空,查看源码可以看出

 if not results:
     return self.filter(sqlalchemy.text('null'))

search.db是whoosh建立并保存索引的地方

另外,我来推荐一下我参考flask_whooshalchemy写的搜索扩展,使用上可能更方便一些
https://github.com/honmaple/flask-msearch

flask不熟,不过你可以尝试打印出最终sql,到你的数据库里查询
或是在数据库里监听你最终运行的sql语句看看是什么原因?

首先最好是贴代码出来吧,这个报错信息并没有给出有效的信息。个人猜测是创建索引的时候没有找到索引文件,从而报错。我使用过Whoosh,但是没有使用过flask_whooshalchemy。使用Whoosh需要配置一个INDEX_DIR,全文搜索是根据这个索引文件来实现的。具体flask_whooshalchemy是怎样的,我就不是很清楚了,所以给不了具体的建议。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题