最近在看短信搜索功能,发现 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*‘,也不行,不知何解?期待大牛现身!!!
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()));
}
代码我给你完整帖出来了.按照我的修改就可以模糊查询了