如何从Android查询SQLite数据库中的相似记录?

发布于 2024-11-05 03:17:00 字数 454 浏览 0 评论 0原文

假设 SQLite 数据库列包含以下值:
U Walther-Schreiber-Platz

使用查询,如果用户搜索以下字符串,我希望找到此记录或任何类似记录:

  • walther schreiber
  • u walther
  • walther-schreiber platz
  • [任何其他类似的字符串]

但是我无法找出任何可以做到这一点的查询。特别是如果用户不输入 - 字符。

示例:
select * from myTable where '%walther schreiber%'; 这样的值不会返回结果,因为缺少 -

谢谢, 罗伯特

Let's say an SQLite database column contains the following value:
U Walther-Schreiber-Platz

Using a query I'd like to find this record, or any similar records, if the user searches for the following strings:

  • walther schreiber
  • u walther
  • walther-schreiber platz
  • [Any other similar strings]

However I cannot figure out any query which would do that. Especially if the user does not enter the - character.

Example:
select * from myTable where value like '%walther schreiber%'; would not return the result because of the missing -.

Thanks,
Robert

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞄了个咪的 2024-11-12 03:17:00

因此,正如我在评论中所说,我认为您可以进行以下查询:

select * from myTable where LOWER(value) like <SearchValue>

我假设您正在以编程方式从用户收集 ,因此能够要执行以下操作: 需要:用户的搜索字符串,适当清理以避免 SQL注入攻击,转换为小写,所有空格转换为“%”,以便它们匹配零个或多个字符......

所以你会(例如):

select * from myTable where LOWER(value) like '%walther%schreiber%'
select * from myTable where LOWER(value) like '%walther-schreiber%platz%'

等等...但是,这确实假设词序是相同的,在您的示例中是...

So, as I said in my comment, I think you can have a query along the lines of:

select * from myTable where LOWER(value) like <SearchValue>

I'm assuming you're collecting the <SearchValue> from the user programmatically, so would be able to do the following: <SearchValue> would need to be: The user's search string, appropriately cleansed to avoid SQL injection attacks, converted to lower case, with all of the spaces converted to '%', so that they match zero or more characters...

So you would have (for example):

select * from myTable where LOWER(value) like '%walther%schreiber%'
select * from myTable where LOWER(value) like '%walther-schreiber%platz%'

etc... however, this does assume that the word order is the same, which in your examples it is...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文