interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / test / fts5near.test

111 lines · 3821 bytes Raw Blame History
1# 2014 Jan 08
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# Tests focused on the NEAR operator.
13#
14
15source [file join [file dirname [info script]] fts5_common.tcl]
16set testprefix fts5near
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20 finish_test
21 return
22}
23
24proc do_near_test {tn doc near res} {
25 uplevel [list do_execsql_test $tn "
26 DELETE FROM t1;
27 INSERT INTO t1 VALUES('$doc');
28 SELECT count(*) FROM t1 WHERE t1 MATCH '$near';
29 " $res]
30}
31
32execsql {
33 CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize = "ascii tokenchars '.'")
34}
35
36do_near_test 1.1 ". . a . . . b . ." { NEAR(a b, 5) } 1
37do_near_test 1.2 ". . a . . . b . ." { NEAR(a b, 4) } 1
38do_near_test 1.3 ". . a . . . b . ." { NEAR(a b, 3) } 1
39do_near_test 1.4 ". . a . . . b . ." { NEAR(a b, 2) } 0
40
41do_near_test 1.5 ". . a . . . b . ." { NEAR(b a, 5) } 1
42do_near_test 1.6 ". . a . . . b . ." { NEAR(b a, 4) } 1
43do_near_test 1.7 ". . a . . . b . ." { NEAR(b a, 3) } 1
44do_near_test 1.8 ". . a . . . b . ." { NEAR(b a, 2) } 0
45
46do_near_test 1.9 ". a b . . . c . ." { NEAR("a b" c, 3) } 1
47do_near_test 1.10 ". a b . . . c . ." { NEAR("a b" c, 2) } 0
48do_near_test 1.11 ". a b . . . c . ." { NEAR(c "a b", 3) } 1
49do_near_test 1.12 ". a b . . . c . ." { NEAR(c "a b", 2) } 0
50
51do_near_test 1.13 ". a b . . . c d ." { NEAR(a+b c+d, 3) } 1
52do_near_test 1.14 ". a b . . . c d ." { NEAR(a+b c+d, 2) } 0
53do_near_test 1.15 ". a b . . . c d ." { NEAR(c+d a+b, 3) } 1
54do_near_test 1.16 ". a b . . . c d ." { NEAR(c+d a+b, 2) } 0
55
56do_near_test 1.17 ". a b . . . c d ." { NEAR(a b c d, 5) } 1
57do_near_test 1.18 ". a b . . . c d ." { NEAR(a b c d, 4) } 0
58do_near_test 1.19 ". a b . . . c d ." { NEAR(a+b c d, 4) } 1
59
60do_near_test 1.20 "a b c d e f g h i" { NEAR(b+c a+b+c+d i, 5) } 1
61do_near_test 1.21 "a b c d e f g h i" { NEAR(b+c a+b+c+d i, 4) } 0
62
63do_near_test 1.22 "a b c d e f g h i" { NEAR(a+b+c+d i b+c, 5) } 1
64do_near_test 1.23 "a b c d e f g h i" { NEAR(a+b+c+d i b+c, 4) } 0
65
66do_near_test 1.24 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 5) } 1
67do_near_test 1.25 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 4) } 0
68
69#-------------------------------------------------------------------------
70# Check that https://sqlite.org/bugs/forumpost/16bb36f7e8 is fixed.
71#
72reset_db
73do_execsql_test 2.0 {
74 CREATE VIRTUAL TABLE t USING fts5(x, tokenize=trigram);
75 INSERT INTO t
76 VALUES('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
77}
78
79do_execsql_test 2.1 {
80 SELECT count(*) FROM t WHERE t MATCH 'NEAR(aaa aaa, 4)';
81} {1}
82
83#-------------------------------------------------------------------------
84# Check that if a NEAR group does not match a row that is matched by
85# another branch of an OR, the auxiliary functions do not see stale or
86# partially populated position lists for the phrases of the NEAR group.
87#
88reset_db
89do_execsql_test 3.0 {
90 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
91 INSERT INTO t1(rowid, a, b) VALUES (1, 'one', 'h e d c');
92 INSERT INTO t1(rowid, a, b) VALUES (2, 'r h c', 'p q s t u');
93}
94
95do_execsql_test 3.1 {
96 SELECT rowid, highlight(t1, 1, '[', ']') FROM t1('b : NEAR(h c, 2) OR r');
97} {1 {[h] e d [c]} 2 {p q s t u}}
98
99do_execsql_test 3.2 {
100 UPDATE t1 SET b = 'x' WHERE rowid = 2;
101 SELECT rowid, snippet(t1, 1, '[', ']', '..', 3)
102 FROM t1('b : NEAR(h c, 2) OR r');
103} {1 {[h] e d..} 2 x}
104
105do_execsql_test 3.3 {
106 CREATE VIRTUAL TABLE t2 USING fts5(a);
107 INSERT INTO t2(a) VALUES ('r h d c');
108 SELECT highlight(t2, 0, '[', ']') FROM t2('NEAR(h "c d") OR r');
109} {{[r] h d c}}
110
111finish_test