如何从Android查询SQLite数据库中的相似记录?
假设 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,正如我在评论中所说,我认为您可以进行以下查询:
我假设您正在以编程方式从用户收集
,因此能够要执行以下操作:
需要:用户的搜索字符串,适当清理以避免 SQL注入攻击,转换为小写,所有空格转换为“%”,以便它们匹配零个或多个字符......所以你会(例如):
等等...但是,这确实假设词序是相同的,在您的示例中是...
So, as I said in my comment, I think you can have a query along the lines of:
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):
etc... however, this does assume that the word order is the same, which in your examples it is...