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 / fts5origintext2.test

146 lines · 4333 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 phrase queries.
13#
14
15source [file join [file dirname [info script]] fts5_common.tcl]
16set testprefix fts5origintext2
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20 finish_test
21 return
22}
23
24sqlite3_fts5_register_origintext db
25do_execsql_test 1.0 {
26 CREATE VIRTUAL TABLE ft USING fts5(
27 x, tokenize="origintext unicode61", tokendata=1
28 );
29}
30
31do_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
45do_execsql_test 1.2 { SELECT rowid FROM ft('hello'); } {1 2 3}
46do_execsql_test 1.3 { SELECT rowid FROM ft('today'); } {4 5 6}
47do_execsql_test 1.4 { SELECT rowid FROM ft('world'); } {7 8 9}
48
49do_execsql_test 1.5 {
50 SELECT count(*) FROM ft_data
51} 3
52
53do_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
77do_execsql_test 1.7 {
78 SELECT count(*) FROM ft_data;
79} 23
80
81do_execsql_test 1.8 { SELECT rowid FROM ft('hello') WHERE rowid>100; } {101}
82
83do_execsql_test 1.9 {
84 DELETE FROM ft;
85 INSERT INTO ft(ft) VALUES('optimize');
86 SELECT count(*) FROM ft_data;
87} {2}
88do_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
101do_execsql_test 1.11 { SELECT rowid FROM ft('hello'); } {1 2 3}
102do_execsql_test 1.12 { SELECT rowid FROM ft('today'); } {4 5 6}
103do_execsql_test 1.13 { SELECT rowid FROM ft('world'); } {7 8 9}
104do_execsql_test 1.14 { SELECT rowid FROM ft('hello') ORDER BY rank; } {1 2 3}
105
106#------------------------------------------------------------------------
107reset_db
108sqlite3_fts5_register_origintext db
109proc 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}
118sqlite3_fts5_create_function db tokens tokens
119
120do_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
129do_execsql_test 2.1 {
130 SELECT tokens(x1) FROM x1('xxx');
131} {
132 {xxx xxx.Xxx xxx.XXX} {xxx xxx}
133}
134
135do_execsql_test 2.2 {
136 UPDATE x1_content SET c0 = 'xxx xxX xxx yyy yyy yyy' WHERE id=1;
137}
138
139do_execsql_test 2.3 {
140 SELECT tokens(x1) FROM x1('xxx');
141} {
142 {xxx {} xxx} {xxx xxx}
143}
144
145finish_test
146