SQLite FTS示例不起作用 [英] SQLite FTS example doesn't work
问题描述
我已经下载了最新的SQLite 3.7.15.2 Shell(Win32),并尝试完全按照
I've downloaded the latest SQLite 3.7.15.2 shell (Win32) and tried to execute one of the FTS examples exactly as it is written at http://sqlite.org/fts3.html#section_3
-- 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中的错误还是只是过时的文档? (正确的语法是什么?).
but in spite of last comment SELECT resulted in empty set. Is it a bug in SQLite or just outdated documentation? (and what is the correct syntax for that?).
对我来说最重要的是查询
What is most important for me is that query
SELECT * FROM docs WHERE docs MATCH '(database OR sqlite) NEAR/5 system';
也不起作用,我需要在我的应用中进行这种类型的查询.还有其他方法可以编写它吗?
doesn't work either and that type of queries I need in my app. Is there any other way to write it so it would work?
推荐答案
文档中的示例使用增强查询语法.
检查PRAGMA compile_options;
是否包含ENABLE_FTS3_PARENTHESIS
.
The example from the documentation uses the enhanced query syntax.
Check that PRAGMA compile_options;
includes ENABLE_FTS3_PARENTHESIS
.
您的NEAR
查询不起作用,这与编译选项无关:
That your NEAR
query does not work is not a problem with compilation options:
> SELECT * FROM docs WHERE docs MATCH '(database OR sqlite) NEAR/5 system';
Error: malformed MATCH expression: [(database OR sqlite) NEAR/5 system]
问题在于,根据文档,NEAR
仅适用于基本搜索表达式:
The problem is that, according to the documentation, NEAR
does work only with basic search expressions:
通过在两个短语,术语或前缀查询之间放置关键字"NEAR"来指定NEAR查询.
A NEAR query is specified by putting the keyword "NEAR" between two phrase, term or prefix queries.
因此,您必须相应地重写搜索表达式:
So you have to rewrite your search expression accordingly:
> 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
这篇关于SQLite FTS示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!