DROP TABLE IF EXISTS TEXTS;
CREATE TABLE TEXTS (text_id int PRIMARY KEY, text ntext,last_update datetime DEFAULT
CURRENT_TIMESTAMP);
DROP TABLE IF EXISTS FTSTEXTS;
CREATE VIRTUAL TABLE FTSTEXTS USING fts5(text,content="TEXTS",content_rowid="text_id",tokenize=unicode61);
Insert into texts (text_id,text) values (1,'first'),(2,'second'),(3,'third'),(4,'fourth');
Insert into ftstexts (rowid,text) values (1,'first'),(2,'second'),(3,'third'),(4,'fourth');
update texts set text='5555' where text_id=2;
update ftstexts set text='5555' where rowid=2;
select text from texts where text_id=(select rowid from ftstexts where text match('second') limit 1);
result is "5555"
在创建表并将第2行的值更新为“ 5555”后,查询
select rowid from ftstexts where text match('second') limit 1
返回2:
如何填充FTS表以从fts搜索中排除“秒”一词?
查询已在SQLITEStudio 3.2.1上运行
答案 0 :(得分:1)
外部内容FTS5表不支持更新。您必须删除一行的旧内容,然后将新内容作为单独的步骤插入。
documentation包含一些示例触发器,用于自动使此类表与保存实际数据的表保持同步。
您可能会使更新触发类似
CREATE TRIGGER texts_au AFTER UPDATE ON texts BEGIN
INSERT INTO ftstexts(ftstexts, rowid, text) VALUES('delete', old.text_id, old.text);
INSERT INTO ftstexts(rowid, text) VALUES (new.text_id, new.text);
END;