我目前有一张诊断表。我想使用 FTS 使代码和描述字段可搜索。据我了解,FTS 表不支持索引,我需要能够非常快速地通过诊断 ID 查找诊断。我是否必须创建第二个虚拟表并复制所有数据以进行全文搜索,或者我是否缺少无需复制所有诊断代码和描述的解决方案?
CREATE TABLE Diagnosis (
diagnosisID INTEGER PRIMARY KEY NOT NULL,
code TEXT,
collect INTEGER NOT NULL,
description TEXT
);
最佳答案
事实证明,FTS 表有一个隐藏的 rowid
字段,您可以在输入数据时填充该字段:
sqlite> create virtual table test1 using fts3;
sqlite> insert into test1 values ("This is a document!");
sqlite> insert into test1(docid,content) values (5,"this is another document");
sqlite> select rowid,* from test1;
1|This is a document!
5|this is another document
您可以在标准表中创建一个整数字段,通过 rowid 引用 FTS 表,然后将您希望进行文本搜索的列移动到 FTS 表中。
您需要的所有信息 here :)
关于SQLite 全文搜索索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8520558/