SQLite FTS5 Match 没有返回任何内容

SQLite FTS5 Match is returning nothing

我有一个 SQLite3 table:

CREATE TABLE "test" (
    "title" TEXT,
    "shortdesc" TEXT,
    "longdesc"  TEXT,
    "id"    TEXT,
    PRIMARY KEY("id")
);

我在其中插入任何内容:

INSERT INTO test (id, title, shortdesc, longdesc) VALUES ("abc", "hello world", "this is a hello world", "a nice hello world article about hello worlds")

然后我创建一个 FTS5 虚拟 table:

CREATE VIRTUAL TABLE IF NOT EXISTS test_fts USING fts5 (
        id,
        title,
        shortdesc,
        longdesc,
        content=test
);

所以我在虚拟中检查数据table:

一切似乎都很好...现在我尝试使用 MATCH 查找文章:

SELECT * FROM test_fts WHERE test_fts MATCH 'hello'

...我什么也没得到。显然我展示的这个数据库只是一个例子,实际数据库也会发生同样的事情。我在不同的计算机(和不同的客户端)上尝试过,我还检查了 FTS5 是否已启用并在其中使用 PRAGMA compile_options 进行了编译,并且 ENABLE_FTS5 在那里,这意味着它已启用。 FTS3 和 4 也会发生同样的事情。

那我错过了什么? SQLite 版本是 3.36.0.

FTS5 table 仍然需要填充。这包括外部内容案例。来自 documentation:

It is still the responsibility of the user to ensure that the contents of an external content FTS5 table are kept up to date with the content table. One way to do this is with triggers. For example:

-- Create a table. And an external content fts5 table to index it.
CREATE TABLE tbl(a INTEGER PRIMARY KEY, b, c);
CREATE VIRTUAL TABLE fts_idx USING fts5(b, c, content='tbl', content_rowid='a');

-- Triggers to keep the FTS index up to date.
CREATE TRIGGER tbl_ai AFTER INSERT ON tbl BEGIN
 INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
END;
CREATE TRIGGER tbl_ad AFTER DELETE ON tbl BEGIN
 INSERT INTO fts_idx(fts_idx, rowid, b, c) VALUES('delete', old.a, old.b, old.c);
END;
CREATE TRIGGER tbl_au AFTER UPDATE ON tbl BEGIN
 INSERT INTO fts_idx(fts_idx, rowid, b, c) VALUES('delete', old.a, old.b, old.c);
 INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
END;

因此,您可以在填充主 table 之前创建 table 和触发器,或者在您的测试用例中,在创建 FTS table 之后,您可以 运行 像这样的查询第一次填充 FTS table:

INSERT INTO test_fts SELECT * FROM test;

那么您的查询将按预期工作。