match子句返回不正确的结果

时间:2012-09-02 17:21:09

标签: sqlite full-text-search fts3

我正在尝试在sqlite中使用FTS3并执行一个未返回所需结果的查询。这是查询:

select * from table1 where col1 MATCH 'rain';

此查询返回包含文本'strain'的col1,我不想要。我想要这个查询的确切副本:

select * from table1 where col1 like '% rain %';

任何建议/意见/帮助?

2 个答案:

答案 0 :(得分:0)

我不确定你为什么得到这个结果。您应该只获得与您发布的MATCH查询匹配的条款的结果。你能发布你的FTS3 CREATE TABLE声明吗?

例如:

SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE VIRTUAL TABLE mail USING fts3(subject, body);
sqlite> INSERT INTO mail(docid, subject, body) VALUES(1, 'software feedback', 'found it too slow');
sqlite> INSERT INTO mail(docid, subject, body) VALUES(2, 'software feedback', 'no feedback');
sqlite> INSERT INTO mail(docid, subject, body) VALUES(3, 'slow lunch order',  'was a software problem');
sqlite> select * from mail where body match 'back';
sqlite> select * from mail where body match 'feedback';
software feedback|no feedback

答案 1 :(得分:0)

对于sqlite数据库中的FTS3 / FTS4,我得出结论,在对任何文本列中的元素进行标记时,简单(至少)忽略'('和')'的默认标记生成器。其他特殊字符也可以检查,因为我怀疑还会有其他人。执行匹配查询时,将忽略这些值。以下是我的方案的测试用例:

create virtual table tab1 using fts3(val text);
insert into tab1 values('this is rain test');
insert into tab1 values('this is strain test');
insert into tab1 values('this is (rain) test with parenthesis');
insert into tab1 values('rain test');
insert into tab1 values('this is rain');
insert into tab1 values('strain test');
insert into tab1 values('this is strain');

执行以下查询后:

select * from tab1 where val MATCH 'rain';

结果是:

this is rain test
this is (rain) test with parenthesis
rain test
this is rain