从SQLite FTS表中获取反向索引

use*_*626 5 database sqlite full-text-search inverted-index

在我使用Sqlite和FTS表在我的应用程序中实现全文搜索功能后,我会感兴趣的是从我的FTS表中检索FULL倒排索引的高效方法.实际上 - 我需要一个结果表,包括所有术语之间的映射 - > docid - >出现次数.

遵循Sqlite FTS 文档 - 在创建表之后

-- Create an FTS4 table
CREATE VIRTUAL TABLE ft USING fts4(x, y);

-- Create an fts4aux table to access the full-text index for table "ft"
CREATE VIRTUAL TABLE ft_terms USING fts4aux(ft);
Run Code Online (Sandbox Code Playgroud)

...和内容插入......

INSERT INTO ft(x, y) VALUES('Apple banana', 'Cherry');
INSERT INTO ft(x, y) VALUES('Banana Date Date', 'cherry');
INSERT INTO ft(x, y) VALUES('Cherry Elderberry', 'Elderberry');
Run Code Online (Sandbox Code Playgroud)

...而不是像FTS AUX表中的所有文件中只有条款和出现次数......

SELECT term, col, documents, occurrences FROM ft_terms;

--     apple       |  *  |  1  |  1
--     apple       |  0  |  1  |  1
--     banana      |  *  |  2  |  2
--     banana      |  0  |  2  |  2
--     cherry      |  *  |  3  |  3
--     cherry      |  0  |  1  |  1
--     cherry      |  1  |  2  |  2
--     date        |  *  |  1  |  2
--     date        |  0  |  1  |  2
--     elderberry  |  *  |  1  |  2
--     elderberry  |  1  |  1  |  1
--     elderberry  |  1  |  1  |  1
Run Code Online (Sandbox Code Playgroud)

我的结果应该如下表所示:

           Term    |col  |docid| occurences
------------------------------------------
--     apple       |  0  |  1  |  1
--     banana      |  0  |  2  |  1
--     cherry      |  0  |  3  |  1
--     cherry      |  1  |  1  |  1
--     cherry      |  1  |  2  |  1
--     date        |  0  |  2  |  2
--     elderberry  |  0  |  3  |  1
--     elderberry  |  1  |  3  |  1
Run Code Online (Sandbox Code Playgroud)

我仍然不确定文档集合中所有术语的简单匹配查询是否足够有效 - 也许有更直接的方法?