我有一个sqlite数据库,其中包含许多我使用webview显示的html内容。现在我想在我的应用中添加搜索功能。我有两个表一个用于类别,另一个表用于子类别。以下是创建查询。
String CREATE_SUBCATEGORY_TABLE = "CREATE VIRTUAL TABLE " + TABLE_SUBCATEGORY_LIST + " USING fts3("
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + KEY_NAME + " TEXT,"
+ KEY_DESC + " TEXT," + KEY_CATEGORY_ID + " INTEGER,"
+ KEY_CONTENT1 + " TEXT," + KEY_CONTENTTYPE1 + " TEXT,"
+ KEY_CONTENT2 + " TEXT," + KEY_CONTENTTYPE2 + " TEXT,"
+ KEY_CONTENT3 + " TEXT," + KEY_CONTENTTYPE3 + " TEXT,"
+ KEY_CONTENT4 + " TEXT," + KEY_CONTENTTYPE4 + " TEXT,"
+ KEY_CONTENT5 + " TEXT," + KEY_CONTENTTYPE5 + " TEXT,"
+ KEY_CONTENT6 + " TEXT," + KEY_CONTENTTYPE6 + " TEXT,"
+ KEY_CONTENT7 + " TEXT," + KEY_CONTENTTYPE7 + " TEXT,"
+ KEY_CONTENT8 + " TEXT," + KEY_CONTENTTYPE8 + " TEXT,"
+ KEY_CONTENT9 + " TEXT," + KEY_CONTENTTYPE9 + " TEXT,"
+ KEY_CONTENT10 + " TEXT," + KEY_CONTENTTYPE10 + " TEXT,"
+ KEY_CONTENT11 + " TEXT," + KEY_CONTENTTYPE11 + " TEXT,"
+ KEY_CONTENT12 + " TEXT," + KEY_CONTENTTYPE12 + " TEXT,"
+ KEY_CONTENT13 + " TEXT," + KEY_CONTENTTYPE13 + " TEXT,"
+ KEY_CONTENT14 + " TEXT," + KEY_CONTENTTYPE14 + " TEXT,"
+ KEY_CONTENT15 + " TEXT," + KEY_CONTENTTYPE15 + " TEXT,"
+ KEY_ORDERID + " INTEGER," + KEY_STATUS + " TEXT,"
+ KEY_UPDATED + " TEXT, FOREIGN KEY (" + KEY_CATEGORY_ID + ") REFERENCES " + CAT_TABLE + "(" + KEY_CATEGORY_ID + ")" + ")";
String CREATE_CATEGORYLIST_TABLE = "CREATE VIRTUAL TABLE " + CAT_TABLE + " USING fts3("
+ KEY_CATEGORY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + KEY_CATNAME + " TEXT,"
+ KEY_CATDESC + " TEXT," + KEY_STATUS + " TEXT," + KEY_ORDERID + " INTEGER " + ")";
所以现在我的所有表都是虚拟表。现在我的搜索查询应该是什么。我创建了以下搜索查询,但我不确定它是否可行。
public Cursor searchByInputText(String inputText) throws SQLException {
SQLiteDatabase myDb = this.getReadableDatabase();
String[] selectionArgs = { inputText };
String query = "SELECT docid as _id, " +
KEY_CATNAME +" ,"+KEY_CATDESC + " from " + CAT_TABLE +
" where " + CAT_TABLE + " MATCH ? '," + selectionArgs + "';";
Cursor mCursor = myDb.rawQuery(query,null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
我想首先在类别表中搜索被搜索的术语,否则搜索子类别表。