简体   繁体   English

我如何从我的 sqlite 数据库中查询和获取数据,即使我的搜索输入有相似的单词彼此分开(不是连续的)

[英]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.

相关问题 如何从持续运行脚本的另一台 PC 访问数据? - How can I access data from my other PC that is continuously running a script? 如何根据查询从搜索结果中突出显示单词? - How can I highlight words from my search result based on my query? 我查询我的 sqlite 数据库并得到结果为 [ ](空白),即使我的数据库有我试图查询的数据 - I query my sqlite database and got the result as [ ] (blank) even when my database has the data I tried to query 我无法连续看到从我的 MySQL 数据库到我的 html 页面的最后插入数据 - I can't see continuously the last insert data from my MySQL database to my html page 我应该如何让Tkinter IRC客户端从IRC服务器连续读取数据? - How should I get my Tkinter IRC client to continuously read data from the IRC server? 在 SQLite 中,如何使用输入框中的文本搜索我的数据库,并将结果显示为文本? - In SQLite, how do I search my database with text from an entry box, and display the result as text? 为什么不能从sqlite3上的数据库中删除? - WHy can't i delete from my database on sqlite3? 我无法从我的 Python sqlite3 数据库中获取 integer - I can't get an integer from my Python sqlite3 database 如何从Django数据库中获取固定输出 - How can I get fixed output from my django database 在QTableWidget中如何打印数据库中的数据? - How can I print data from my database while in QTableWidget?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM