3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
16 # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
17 ifcapable !fts3 { finish_test ; return }
19 set testprefix fts3offsets
20 set sqlite_fts3_enable_parentheses 1
22 proc extract {offsets text} {
26 foreach {t i s n} $offsets {
27 lappend off [list $s $n]
29 set off [lsort -integer -index 0 $off]
34 append res [string range $text $iOff $s-1]
36 append res [string range $text $s [expr $s+$n-1]]
40 append res [string range $text $iOff end]
44 db func extract extract
47 do_execsql_test 1.1.0 {
48 CREATE VIRTUAL TABLE xx USING fts3(x);
49 INSERT INTO xx VALUES('A x x x B C x x');
50 INSERT INTO xx VALUES('A B C x B x x C');
51 INSERT INTO xx VALUES('A x x B C x x x');
53 do_execsql_test 1.1.1 {
54 SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
56 1 {(A) x x x (B) (C) x x}
57 2 {(A) (B) (C) x (B) x x C}
58 3 {(A) x x (B) (C) x x x}
63 INSERT INTO xx VALUES('A x x x B C x x');
64 INSERT INTO xx VALUES('A x x C x x x C');
65 INSERT INTO xx VALUES('A x x B C x x x');
67 do_execsql_test 1.2.1 {
68 SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
70 1 {(A) x x x (B) (C) x x}
72 3 {(A) x x (B) (C) x x x}
77 INSERT INTO xx(rowid, x) VALUES(1, 'A B C');
78 INSERT INTO xx(rowid, x) VALUES(2, 'A x');
79 INSERT INTO xx(rowid, x) VALUES(3, 'A B C');
80 INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B');
81 INSERT INTO xx(rowid, x) VALUES(5, 'A x x x x x x x x x C');
82 INSERT INTO xx(rowid, x) VALUES(6, 'A x x x x x x x x x x x B');
83 INSERT INTO xx(rowid, x) VALUES(7, 'A B C');
85 do_execsql_test 1.3.1 {
86 SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)';
91 4 {(A) (B) (C) x x x x x x x B}
92 5 {(A) x x x x x x x x x C}
93 6 {(A) x x x x x x x x x x x B}
100 INSERT INTO xx(rowid, x) VALUES(7, 'A B C');
101 INSERT INTO xx(rowid, x) VALUES(6, 'A x');
102 INSERT INTO xx(rowid, x) VALUES(5, 'A B C');
103 INSERT INTO xx(rowid, x) VALUES(4, 'A B C x x x x x x x B');
104 INSERT INTO xx(rowid, x) VALUES(3, 'A x x x x x x x x x C');
105 INSERT INTO xx(rowid, x) VALUES(2, 'A x x x x x x x x x x x B');
106 INSERT INTO xx(rowid, x) VALUES(1, 'A B C');
108 do_execsql_test 1.4.1 {
109 SELECT oid,extract(offsets(xx), x) FROM xx WHERE xx MATCH 'a OR (b NEAR/1 c)'
115 4 {(A) (B) (C) x x x x x x x B}
116 3 {(A) x x x x x x x x x C}
117 2 {(A) x x x x x x x x x x x B}
122 set sqlite_fts3_enable_parentheses 0