最近在看短信搜索功能,发现 MmsSmsProvider.java 中的SQL语句不能很好的搜索现象,不知道是什么原因,部分代码:String searchString = uri.getQueryParameter("pattern");
String query = String.format("SELECT _id, index_text, source_id, table_to_use, offsets(words) FROM words WHERE words MATCH '%s*' LIMIT 50;", searchString);
if ( sortOrder != null
|| selection != null
|| selectionArgs != null
|| projection != null) {
throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" +
"with this query");
} cursor = db.rawQuery(query, null);
执行这条SQL语句,如果短信内容是:“短信信息搜索”,只有输入“短信”才能查到结果,输入“信息”却查不到结果,也就是说输入第一个字符串才能查到,而且我把query中的‘%s*'改为‘*%s*‘,也不行,不知何解?期待大牛现身!!!
String query = String.format("SELECT _id, index_text, source_id, table_to_use, offsets(words) FROM words WHERE words MATCH '%s*' LIMIT 50;", searchString);
if ( sortOrder != null
|| selection != null
|| selectionArgs != null
|| projection != null) {
throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" +
"with this query");
} cursor = db.rawQuery(query, null);
执行这条SQL语句,如果短信内容是:“短信信息搜索”,只有输入“短信”才能查到结果,输入“信息”却查不到结果,也就是说输入第一个字符串才能查到,而且我把query中的‘%s*'改为‘*%s*‘,也不行,不知何解?期待大牛现身!!!
解决方案 »
- 模拟器今天出现一个比较恶心的问题,求大婶们看看····
- 怎么使左右两个EditText上下滚动的时候同时进行?
- 救助,在地图上绘制自己的图片,移动的时候怎么跟着显示
- AndroidManifest.xml的问题
- 如何往textview加入字符串
- 不问明白了不罢休,Android LKM问题
- 可以练习android开发了,有点兴奋!散分
- java.net.SocketException: No route to host报错
- JNI 高手进:jni下调用sigaction注册的handle函数会不会被JVM 释放
- Android Ethernet开发
- 求救!!!ADT升级到17.0版本出现奇怪的问题!
- 请教关于编译skia的问题
String query = String.format("SELECT _id, index_text, source_id, table_to_use FROM words WHERE index_text LIKE '%%%s%%' LIMIT 50;", searchString);
然后在suggestionsProvider.java computeRows() 函数中修改 返回数据库的解析方式HashSet<String> got = new HashSet<String>(); int textColumn = mDatabaseCursor.getColumnIndex("index_text");
int count = mDatabaseCursor.getCount();
for (int i = 0; i < count; i++) {
mDatabaseCursor.moveToPosition(i);
String message = mDatabaseCursor.getString(textColumn);
String candidate = message.substring(0, message.length());
String key = candidate.toLowerCase();
if (got.contains(key)) {
continue;
}
got.add(key);
mRows.add(new Row(i, message, 0, message.length()));
}
代码我给你完整帖出来了.按照我的修改就可以模糊查询了