我在 android 中创建一个 fts4 表,我批量插入大量行,然后按照sqlite 文档中的建议进行优化
我在android中使用以下代码
public void indexFts() {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("CREATE VIRTUAL TABLE IF NOT EXISTS pageTextSearch USING fts4(content=\"\", page)");
db.beginTransaction();
try {
SQLiteStatement populateFTS_Statement = db.compileStatement(INSERT INTO pageTextSearch(docid,page)VALUES (?, ?)); //pre-compiled sql statement
while (allPagesCursor.moveToNext()) {
populateFTS_Statement.clearBindings();
populateFTS_Statement.bindLong(1, allPagesCursor.getLong(0));
populateFTS_Statement.bindString(2, allPagesCursor.getString(1));
populateFTS_Statement.executeInsert();
}
db.execsql( INSERT INTO pageTextSearch(pageTextSearch)VALUES('optimize'));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
现在,当我使用 match 查询 fts 表时,无论查询如何,我都会得到 0 结果:
db.rawQuery(SELECT docid FROM pageTextSearch WHERE page MATCH ?
, new String[]{"a"});
将给出一个空光标