我在Android应用中使用SQLite3 C API。我想在表格中实现全文搜索。
在其中创建了一个虚拟表:
create VIRTUAL TABLE IF NOT EXISTS call_record USING fts3(_id int, call_id text not null, caller text not null, recipient text not null, record_type text not null, start_time text not null, end_time text not null, UNIQUE(call_id) PRIMARY KEY(_id));
在其中插入少量记录:
INSERT INTO call_record (call_id, caller, recipient, record_type, start_time, end_time) VAlUES (123, 'John', 'Jane', 0, 12345, 12344);
INSERT INTO call_record (call_id, caller, recipient, record_type, start_time, end_time) VAlUES (456, 'Jane', 'Mike', 0, 12345, 12344);
INSERT INTO call_record (call_id, caller, recipient, record_type, start_time, end_time) VAlUES (789, 'Ram', 'Shyam', 0, 12345, 12344);
正确获取记录:
Select * from Call_record;
正确获取记录:
Select * from Call_record where caller LIKE 'j%';
但匹配关键字未给出任何结果:
SELECT call_id, caller, recipient, start_time, end_time FROM call_record WHERE caller MATCH 'j*';
为了验证我的查询和方法,我安装了DB Browser for SQLite并执行了相同的操作并使用匹配正确获得结果。
当我阅读有关SQLite3 C API的更多内容时,会在那里提到应该使用SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER调用sqlite3_db_config,所以我做了确切的事情,但没有任何问题:
rc = sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, NULL);
if (rc) {
LOGE("Can'tconfigure SQLite FTS3: %s", sqlite3_errmsg(db));
return -1;
}
任何帮助/建议都将受到高度赞赏。
注意:上述查询是从控制台日志复制的实际查询。