Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/test/fts5tokendata.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / fts5 / test / fts5tokendata.test` 168 lines ยท 4226 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 15 source [file join [file dirname [info script]] fts5_common.tcl] 16 set testprefix fts5tokendata 17 18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 19 ifcapable !fts5 { 20 finish_test 21 return 22 } 23 24 foreach_detail_mode $testprefix { 25 26 sqlite3_fts5_register_origintext db 27 fts5_aux_test_functions db 28 proc b {x} { string map [list "\0" "."] $x } 29 db func b b 30 31 do_execsql_test 1.0 { 32 CREATE VIRTUAL TABLE ft USING fts5(a, b, tokendata=1, 33 tokenize="origintext unicode61", detail=%DETAIL% 34 ); 35 CREATE VIRTUAL TABLE vocab USING fts5vocab(ft, instance); 36 } 37 38 do_execsql_test 1.1 { 39 INSERT INTO ft(rowid, a, b) VALUES 40 (1, 'Pedagog Pedal Pedant', 'Peculier Day Today'), 41 (2, 'Pedant pedantic pecked', 'Peck Penalize Pen'); 42 43 INSERT INTO ft(rowid, a, b) VALUES 44 (3, 'Penalty Pence Penciled', 'One Two Three'), 45 (4, 'Pedant Pedal Pedant', 'Peculier Day Today'); 46 } 47 48 do_execsql_test 1.2 { 49 SELECT DISTINCT b(term) FROM vocab 50 } { 51 day.Day one.One peck.Peck pecked peculier.Peculier pedagog.Pedagog 52 pedal.Pedal pedant.Pedant pedantic pen.Pen penalize.Penalize 53 penalty.Penalty pence.Pence penciled.Penciled three.Three 54 today.Today two.Two 55 } 56 57 do_execsql_test 1.3.1 { 58 SELECT rowid FROM ft('pe*') 59 } { 60 1 2 3 4 61 } 62 63 do_execsql_test 1.3.2 { 64 SELECT rowid FROM ft('pe*') ORDER BY rowid DESC 65 } { 66 4 3 2 1 67 } 68 69 if {"%DETAIL%"!="none"} { 70 do_execsql_test 1.3.3 { 71 SELECT rowid FROM ft WHERE a MATCH 'pe*' ORDER BY rowid DESC 72 } { 73 4 3 2 1 74 } 75 } 76 77 do_execsql_test 1.4 { 78 SELECT rowid, b( fts5_test_insttoken(ft, 0, 0) ) FROM ft('pedant') 79 } { 80 1 pedant.Pedant 81 2 pedant.Pedant 82 4 pedant.Pedant 83 } 84 85 do_execsql_test 1.5 { 86 SELECT rowid, b( fts5_test_insttoken(ft, 0, 0) ) FROM ft('pe*') 87 } { 88 1 pedagog.Pedagog 89 2 pedant.Pedant 90 3 penalty.Penalty 91 4 pedant.Pedant 92 } 93 94 do_execsql_test 1.6 { 95 SELECT rowid, fts5_test_poslist(ft) FROM ft('pe*') 96 } { 97 1 {0.0.0 0.0.1 0.0.2 0.1.0} 98 2 {0.0.0 0.0.1 0.0.2 0.1.0 0.1.1 0.1.2} 99 3 {0.0.0 0.0.1 0.0.2} 100 4 {0.0.0 0.0.1 0.0.2 0.1.0} 101 } 102 103 reset_db 104 do_execsql_test 2.0 { 105 CREATE VIRTUAL TABLE f USING fts5(a, tokendata=1); 106 INSERT INTO f(f, rank) VALUES('pgsz', 64); 107 WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100) 108 INSERT INTO f(rowid, a) SELECT i, iif(i<100, 'u0', 'v') FROM s; 109 } 110 111 do_execsql_test 2.1 { 112 SELECT count(*) FROM f('u1'); 113 } {0} 114 115 do_execsql_test 2.2 { 116 PRAGMA integrity_check 117 } {ok} 118 119 reset_db 120 sqlite3_fts5_register_origintext db 121 do_execsql_test 3.0 { 122 CREATE VIRTUAL TABLE ft USING fts5(a, tokendata=1, 123 tokenize="origintext unicode61", detail=%DETAIL% 124 ); 125 INSERT INTO ft(ft, rank) VALUES('pgsz', 64); 126 INSERT INTO ft(ft, rank) VALUES('automerge', 0); 127 } 128 129 do_test 3.1 { 130 for {set s 0} {$s < 4} {incr s} { 131 execsql { 132 WITH r(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM r WHERE i<2000) 133 INSERT INTO ft(rowid, a) 134 SELECT i*4+$s, iif(i%2, 'xyz', 'Xyz') FROM r; 135 } 136 } 137 execsql { SELECT count(*) FROM ft_idx WHERE pgno & 1 } 138 } {8} 139 140 proc reads {} { 141 db one {SELECT ft FROM ft WHERE ft MATCH '*reads'} 142 } 143 144 do_test 3.2 { 145 set nRead [reads] 146 set res [execsql { SELECT rowid FROM ft('xyz') }] 147 set nReadFull [expr [reads] - $nRead] 148 llength $res 149 } {8000} 150 151 do_execsql_test 3.3 { 152 SELECT rowid FROM ft('xyz') WHERE rowid BETWEEN 7990 AND 8000 153 } {7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000} 154 155 do_test 3.4 { 156 set nRead [reads] 157 execsql { SELECT rowid FROM ft('xyz') WHERE rowid BETWEEN 7990 AND 8000 } 158 set nReadRange [expr [reads] - $nRead] 159 expr {$nReadRange*4 < $nReadFull} 160 } {1} 161 162 do_execsql_test 3.5 { 163 INSERT INTO ft(ft) VALUES('integrity-check'); 164 } 165 } 166 167 finish_test 168