微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLite FTS示例不起作用

我已经下载了最新的sqlite 3.7.15.2 shell(Win32),并尝试完全按照 http://sqlite.org/fts3.html#section_3编写的方式执行其中一个FTS示例

-- Virtual table declaration
CREATE VIRTUAL TABLE docs USING fts3();

-- Virtual table data
INSERT INTO docs(docid,content) VALUES(1,'a database is a software system');
INSERT INTO docs(docid,content) VALUES(2,'sqlite is a software system');
INSERT INTO docs(docid,content) VALUES(3,'sqlite is a database');

-- Return the set of documents that contain the term "sqlite",and the
-- term "database". This query will return the document with docid 3 only.
SELECT * FROM docs WHERE docs MATCH 'sqlite AND database';

但是尽管有最后的评论SELECT导致了空集.它是sqlite中的错误还是过时的文档? (那是什么语法?).

对我来说最重要的是查询

SELECT * FROM docs WHERE docs MATCH '(database OR sqlite) NEAR/5 system';

在我的应用程序中我需要的那种查询也不起作用.有没有其他方法可以写它以便它可以工作?

解决方法

文档中的示例使用 enhanced query syntax.
检查PRAGMA compile_options;包括ENABLE_FTS3_PARENTHESIS.

您的NEAR查询不起作用不是编译选项的问题:

> SELECT * FROM docs WHERE docs MATCH '(database OR sqlite) NEAR/5 system';
Error: malformed MATCH expression: [(database OR sqlite) NEAR/5 system]

问题是,根据文档,NEAR仅适用于基本搜索表达式:

A NEAR query is specified by putting the keyword “NEAR” between two phrase,term or prefix queries.

因此,您必须相应地重写搜索表达式:

> SELECT * FROM docs WHERE docs MATCH '(database NEAR/5 system) OR (sqlite NEAR/5 system)';
a database is a software system
sqlite is a software system

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐