[英]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)
I have a blog search function on my website.我在我的网站上有一个博客搜索 function。
This is my search input: children lazy这是我的搜索输入:儿童懒惰
I have a column in my SQLite database that is called: Children is getting lazy我的 SQLite 数据库中有一个名为:儿童越来越懒惰的列
I use the codes(Python) below to query the data:我使用下面的代码(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())
However using the codes above, I cannot shows the result of the column "Children is getting lazy" with the search input "children lazy".但是,使用上面的代码,我无法使用搜索输入“儿童懒惰”显示“儿童变得懒惰”列的结果。 If I make my search result as "children is", the column's data will show.
如果我将搜索结果设为“children is”,则会显示该列的数据。 I wonder if my problem is because of "ilike" in my query codes.
我想知道我的问题是否是因为我的查询代码中的“ilike”。
split the sraach string by white space and join with '%'用空格分割 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.