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

Python 如何从sqlite数据库中查询和获取数据,即使我的搜索输入具有彼此分离的相似单词(不是连续的),python,sql,sqlite,sqlalchemy,Python,Sql,Sqlite,Sqlalchemy,我的网站上有一个博客搜索功能 这是我的搜索输入:children lazy 在我的SQLite数据库中有一列名为:Children is getting lazy 我使用下面的代码(Python)查询数据: many_posts0 = BlogPost.query.filter(or_((BlogPost.problem_name.ilike("%" + form.search.data + "%")),(BlogPost.text.ilike("%" + form.search.data +

我的网站上有一个博客搜索功能

这是我的搜索输入:children lazy

在我的SQLite数据库中有一列名为:Children is getting lazy

我使用下面的代码(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 lazy”显示“Children is Get lazy”列的结果。如果我将搜索结果设置为“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())

嗨@gelonida!非常感谢你多次帮助我!如果你能帮我解决我的新问题,我将不胜感激:(如果这让你烦恼,请不要报告我……告诉我,我会停止这样做。)对我好。因此,如果用户愿意,没有任何官方方式允许他们之间的私人消息(至少没有,我知道)。所以,在我找到一个更“干净”的官方解决方案之前,请继续这样做。如果我对一个新建议的问题没有反应,那么假设这不是因为我很忙,就是因为我不知道答案。如果我想让你停下来,我会明确地告诉你。快乐编码。对所有人:如果其他人知道更好的方法来处理这个问题,那么请告诉我和更新的变化,这样我们就不会污染评论频道。我愿意接受建议。谢谢@gelonida!!