search

Home  >  Q&A  >  body text

python - flask中sqlalchemy如何模糊查询

因为现在做一个查询功能,输入一个字符串,去查询匹配的内容,这个字符串可能存在于多个字段。

现在参考用了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了吧。。。求大神推荐个解决办法

巴扎黑巴扎黑2804 days ago940

reply all(4)I'll reply

  • PHP中文网

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦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.

    reply
    0
  • 高洛峰

    高洛峰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%'))

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:59:46

    There is wood, there is wood

    reply
    0
  • Cancelreply