Debian Codegraph @

ext/fts5/test/fts5origintext2.test

raw
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 phrase queries.
13 #
14
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5origintext2
17
18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19 ifcapable !fts5 {
20 finish_test
21 return
22 }
23
24 sqlite3_fts5_register_origintext db
25 do_execsql_test 1.0 {
26 CREATE VIRTUAL TABLE ft USING fts5(
27 x, tokenize="origintext unicode61", tokendata=1
28 );
29 }
30
31 do_execsql_test 1.1 {
32 BEGIN;
33 INSERT INTO ft VALUES('Hello');
34 INSERT INTO ft VALUES('hello');
35 INSERT INTO ft VALUES('HELLO');
36 INSERT INTO ft VALUES('today');
37 INSERT INTO ft VALUES('today');
38 INSERT INTO ft VALUES('today');
39 INSERT INTO ft VALUES('World');
40 INSERT INTO ft VALUES('world');
41 INSERT INTO ft VALUES('WORLD');
42 COMMIT;
43 }
44
45 do_execsql_test 1.2 { SELECT rowid FROM ft('hello'); } {1 2 3}
46 do_execsql_test 1.3 { SELECT rowid FROM ft('today'); } {4 5 6}
47 do_execsql_test 1.4 { SELECT rowid FROM ft('world'); } {7 8 9}
48
49 do_execsql_test 1.5 {
50 SELECT count(*) FROM ft_data
51 } 3
52
53 do_execsql_test 1.6 {
54 DELETE FROM ft;
55 INSERT INTO ft(ft, rank) VALUES('pgsz', 64);
56 BEGIN;
57 WITH s(i) AS (
58 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
59 )
60 INSERT INTO ft SELECT 'Hello Hello Hello Hello Hello Hello Hello' FROM s;
61 INSERT INTO ft VALUES ('hELLO hELLO hELLO');
62 INSERT INTO ft VALUES('today today today today today today today');
63 INSERT INTO ft VALUES('today today today today today today today');
64 INSERT INTO ft VALUES('today today today today today today today');
65 INSERT INTO ft VALUES('today today today today today today today');
66 INSERT INTO ft VALUES('today today today today today today today');
67 INSERT INTO ft VALUES('today today today today today today today');
68 INSERT INTO ft VALUES('World World World World World World World');
69 INSERT INTO ft VALUES('world world world world world world world');
70 INSERT INTO ft VALUES('WORLD WORLD WORLD WORLD WORLD WORLD WORLD');
71 INSERT INTO ft VALUES('World World World World World World World');
72 INSERT INTO ft VALUES('world world world world world world world');
73 INSERT INTO ft VALUES('WORLD WORLD WORLD WORLD WORLD WORLD WORLD');
74 COMMIT;
75 }
76
77 do_execsql_test 1.7 {
78 SELECT count(*) FROM ft_data;
79 } 23
80
81 do_execsql_test 1.8 { SELECT rowid FROM ft('hello') WHERE rowid>100; } {101}
82
83 do_execsql_test 1.9 {
84 DELETE FROM ft;
85 INSERT INTO ft(ft) VALUES('optimize');
86 SELECT count(*) FROM ft_data;
87 } {2}
88 do_execsql_test 1.10 {
89 BEGIN;
90 INSERT INTO ft VALUES('Hello');
91 INSERT INTO ft VALUES('hello');
92 INSERT INTO ft VALUES('HELLO');
93 INSERT INTO ft VALUES('today');
94 INSERT INTO ft VALUES('today');
95 INSERT INTO ft VALUES('today');
96 INSERT INTO ft VALUES('World');
97 INSERT INTO ft VALUES('world');
98 INSERT INTO ft VALUES('WORLD');
99 }
100
101 do_execsql_test 1.11 { SELECT rowid FROM ft('hello'); } {1 2 3}
102 do_execsql_test 1.12 { SELECT rowid FROM ft('today'); } {4 5 6}
103 do_execsql_test 1.13 { SELECT rowid FROM ft('world'); } {7 8 9}
104 do_execsql_test 1.14 { SELECT rowid FROM ft('hello') ORDER BY rank; } {1 2 3}
105
106 #------------------------------------------------------------------------
107 reset_db
108 sqlite3_fts5_register_origintext db
109 proc tokens {cmd} {
110 set ret [list]
111 for {set iTok 0} {$iTok < [$cmd xInstCount]} {incr iTok} {
112 set txt [$cmd xInstToken $iTok 0]
113 set txt [string map [list "\0" "."] $txt]
114 lappend ret $txt
115 }
116 set ret
117 }
118 sqlite3_fts5_create_function db tokens tokens
119
120 do_execsql_test 2.0 {
121 CREATE VIRTUAL TABLE x1 USING fts5(
122 v, tokenize="origintext unicode61", tokendata=1, detail=none
123 );
124
125 INSERT INTO x1 VALUES('xxx Xxx XXX yyy YYY yyy');
126 INSERT INTO x1 VALUES('xxx yyy xxx yyy yyy yyy');
127 }
128
129 do_execsql_test 2.1 {
130 SELECT tokens(x1) FROM x1('xxx');
131 } {
132 {xxx xxx.Xxx xxx.XXX} {xxx xxx}
133 }
134
135 do_execsql_test 2.2 {
136 UPDATE x1_content SET c0 = 'xxx xxX xxx yyy yyy yyy' WHERE id=1;
137 }
138
139 do_execsql_test 2.3 {
140 SELECT tokens(x1) FROM x1('xxx');
141 } {
142 {xxx {} xxx} {xxx xxx}
143 }
144
145 finish_test
146