![](/img/trans.png)
[英]How can I access data from my other PC that is continuously running a script?
[英]How can I query and get data from my sqlite database even when my search input have similar words that is apart from each other (not continuously)
我在我的网站上有一个博客搜索 function。
这是我的搜索输入:儿童懒惰
我的 SQLite 数据库中有一个名为:儿童越来越懒惰的列
我使用下面的代码(Python)来查询数据:
many_posts0 = BlogPost.query.filter(or_((BlogPost.problem_name.ilike("%" + form.search.data + "%")),(BlogPost.text.ilike("%" + form.search.data + "%")))).order_by(BlogPost.date.desc())
但是,使用上面的代码,我无法使用搜索输入“儿童懒惰”显示“儿童变得懒惰”列的结果。 如果我将搜索结果设为“children is”,则会显示该列的数据。 我想知道我的问题是否是因为我的查询代码中的“ilike”。
用空格分割 sraach 字符串并加入 '%'
# split words and join with "%"
search_string = "%" + "%".join(search_data.split()) + "%"
many_posts0 = BlogPost.query.filter(or_((BlogPost.problem_name.ilike(search_string)),(BlogPost.text.ilike("%" + form.search.data + "%")))).order_by(BlogPost.date.desc())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.