SQLite的喜欢另类REGEXP的,任何Word的比赛开始 [英] SQLite LIKE alternative for REGEXP, Match Start of Any Word
问题描述
这似乎并不可能在Android的一个SQLite查询中使用REGEXP。如果可能的话,请点我在正确的方向。
It does not seem possible to use REGEXP in a SQLite query in Android. If it is possible, please point me in the right direction.
有没有使用LIKE条件来查询在结果的任何单词的开头的前pression的方法吗?
Is there a way to use a LIKE condition to query for an expression at the beginning of any word in the result?
例如:
条目:结果
1.最小结果
2.铝结果
3.最后一分钟
Entries:
1. Minimum
2. Aluminum
3. Last Minute
查询:结果
分
所需的结果结果
(1)最小结果
(3)最后一分钟
Desired Result
(1) Minimum
(3) Last Minute
不会结果
(2)铝
NOT
(2) Aluminum
这基本上是我目前的code,这将返回(2)铝:
This is basically my current code, which would return (2)Aluminum:
public Cursor search(String query) {
return mDb.query(TABLE, COLUMNS, KEY_NAME +" like ?", new String[] { "%"+query+"%" }, null, null, null);
}
任何帮助将大大AP preciated!
Any help will be greatly appreciated!
推荐答案
这有点一个黑客攻击的,但是......
It's somewhat of a hack, but...
foo LIKE 'bar%' OR foo LIKE '% bar%'
可能会为您的需求(在发现富,酒吧在单词的开头)工作。如果你也想标点符号作为分隔符字,你就必须添加或条款为该以及(因此它是一个黑客)。
might work for your needs (finding "bar" at the beginning of a word in "foo"). If you also want punctuation to serve as word delimiters, you'd have to add OR clauses for that as well (hence why it's a hack).
这篇关于SQLite的喜欢另类REGEXP的,任何Word的比赛开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!