因为现在做一个查询功能,输入一个字符串,去查询匹配的内容,这个字符串可能存在于多个字段。
现在参考用了Flask-WhooshAlchemy来做,但是查询结果如下:
hosts.query.whoosh_search('ce').all()
[]
hosts.query.whoosh_search('ceshi').all()
[<Host u'\u6d4b\u8bd5'>]
hosts.query.whoosh_search('ces').all()
[]
hosts.query.whoosh_search('esh').all()
[]
查询"ceshi"的时候又结果,而查询"ce"的时候竟然查询不出来,这也太2了吧。。。求大神推荐个解决办法
PHP中文网2017-04-17 14:59:46
I have never used Flask-WhooshAlchemy, but judging from your expression, it may be that the fuzzy matching is written incorrectly as @digwtx said, or the length may be limited.
There is another possible reason why you cannot find the result. If you are using MySQL, MySQL limits the minimum matching character length. The default length is 4. Only if it is greater than 4 characters will the matching result details be available
Basic query details of SQLAlchemy in flask
伊谢尔伦2017-04-17 14:59:46
whoosh_index This method initializes the full-text index. In order to maintain synchronization between the database and the full-text search engine, delete all existing data in the database and start again.
高洛峰2017-04-17 14:59:46
It’s not like 2, it’s just that you didn’t choose the right method, for example:
Article.query.filter(Article.title.ilike('%ce%'))