How to create virtual table FTS with external sqlite content table?

时间:2019-04-08 13:17:44

标签: sqlite fts4

I want to create a SQLite virtual table with a content of a real one.

I have a small sample which demonstrates my problem. I already red the official tutorial, but can't find anything wrong in this code. Some users use a rebuild option, but it doesn't work for me.

CREATE TABLE if NOT EXISTS posts (a INTEGER PRIMARY KEY);  
INSERT OR IGNORE INTO posts (a) VALUES(510000);  
INSERT OR IGNORE INTO posts (a) VALUES(510001);  
INSERT OR IGNORE INTO posts (a) VALUES(510300);  
CREATE VIRTUAL TABLE IF NOT EXISTS posts_fts using fts5(content=posts, content_rowid=a, a);  

SELECT * FROM posts_fts where posts_fts MATCH '10' ORDER BY a ASC;

If I run this, I get:

0 rows returned in 2ms from: SELECT * FROM posts_fts where posts_fts match '10' ORDER BY a ASC;

Does anyone have an idea wat I do wrong?

1 个答案:

答案 0 :(得分:0)

“ 10”不是FTS表中的令牌。

来自the doc

  

4.3.1。 Unicode61令牌生成器

     

unicode标记程序将所有unicode字符分类为   “分隔符”或“令牌”字符。默认情况下,所有空间和   考虑了Unicode 6.1定义的标点符号   分隔符,所有其他字符作为标记字符。更多   具体来说,所有分配给一般类别的unicode字符   以“ L”或“ N”(特别是字母和数字)开头或   类别“ Co”(“其他私人用途”)被视为令牌。所有其他   字符是分隔符。

     

一个或多个令牌字符的每次连续运行都被认为是   成为令牌。根据规则,分词器不区分大小写   由Unicode 6.1定义。

也来自the doc

  

3.2。 FTS5短语

     

FTS查询由词组组成。短语是一个的有序列表   或更多令牌。

您可以尝试“前缀查询”,即MATCH "5*"来查看结果。