Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/ext/fts5/test/fts5ae.test

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # 2014 June 17
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 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS5 module.
13 #
14 #
15
16 source [file join [file dirname [info script]] fts5_common.tcl]
17 set testprefix fts5ae
18
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
20 ifcapable !fts5 {
21 finish_test
22 return
23 }
24
25 do_execsql_test 1.0 {
26 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
27 INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
28 }
29
30 do_execsql_test 1.1 {
31 INSERT INTO t1 VALUES('hello', 'world');
32 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
33 } {1}
34
35 do_execsql_test 1.2 {
36 INSERT INTO t1 VALUES('world', 'hello');
37 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
38 } {1 2}
39
40 do_execsql_test 1.3 {
41 INSERT INTO t1 VALUES('world', 'world');
42 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
43 } {1 2}
44
45 do_execsql_test 1.4.1 {
46 INSERT INTO t1 VALUES('hello', 'hello');
47 }
48
49 do_execsql_test 1.4.2 {
50 SELECT rowid FROM t1 WHERE t1 MATCH 'hello' ORDER BY rowid ASC;
51 } {1 2 4}
52
53 fts5_aux_test_functions db
54
55 #-------------------------------------------------------------------------
56 #
57 do_execsql_test 2.0 {
58 CREATE VIRTUAL TABLE t2 USING fts5(x, y);
59 INSERT INTO t2 VALUES('u t l w w m s', 'm f m o l t k o p e');
60 INSERT INTO t2 VALUES('f g q e l n d m z x q', 'z s i i i m f w w f n g p');
61 }
62
63 do_execsql_test 2.1 {
64 SELECT rowid, fts5_test_poslist(t2) FROM t2
65 WHERE t2 MATCH 'm' ORDER BY rowid;
66 } {
67 1 {0.0.5 0.1.0 0.1.2}
68 2 {0.0.7 0.1.5}
69 }
70
71 do_execsql_test 2.2 {
72 SELECT rowid, fts5_test_poslist(t2) FROM t2
73 WHERE t2 MATCH 'u OR q' ORDER BY rowid;
74 } {
75 1 {0.0.0}
76 2 {1.0.2 1.0.10}
77 }
78
79 do_execsql_test 2.3 {
80 SELECT rowid, fts5_test_poslist(t2) FROM t2
81 WHERE t2 MATCH 'y:o' ORDER BY rowid;
82 } {
83 1 {0.1.3 0.1.7}
84 }
85
86 #-------------------------------------------------------------------------
87 #
88 do_execsql_test 3.0 {
89 CREATE VIRTUAL TABLE t3 USING fts5(x, y);
90 INSERT INTO t3 VALUES( 'j f h o x x a z g b a f a m i b', 'j z c z y x w t');
91 INSERT INTO t3 VALUES( 'r c', '');
92 }
93
94 do_execsql_test 3.1 {
95 SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(a b)';
96 } {
97 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15}
98 }
99
100 do_execsql_test 3.2 {
101 SELECT rowid, fts5_test_poslist(t3) FROM t3 WHERE t3 MATCH 'NEAR(r c)';
102 } {
103 2 {0.0.0 1.0.1}
104 }
105
106 do_execsql_test 3.3 {
107 INSERT INTO t3
108 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o');
109 SELECT rowid, fts5_test_poslist(t3)
110 FROM t3 WHERE t3 MATCH 'a OR b AND c';
111 } {
112 1 {0.0.6 1.0.9 0.0.10 0.0.12 1.0.15 2.1.2}
113 3 0.0.5
114 }
115
116 #-------------------------------------------------------------------------
117 #
118 do_execsql_test 4.0 {
119 CREATE VIRTUAL TABLE t4 USING fts5(x, y);
120 INSERT INTO t4
121 VALUES('k x j r m a d o i z j', 'r t t t f e b r x i v j v g o');
122 }
123
124 do_execsql_test 4.1 {
125 SELECT rowid, fts5_test_poslist(t4) FROM t4 WHERE t4 MATCH 'a OR b AND c';
126 } {
127 1 0.0.5
128 }
129
130 #-------------------------------------------------------------------------
131 # Test that the xColumnSize() and xColumnAvgsize() APIs work.
132 #
133 reset_db
134 fts5_aux_test_functions db
135
136 do_execsql_test 5.1 {
137 CREATE VIRTUAL TABLE t5 USING fts5(x, y);
138 INSERT INTO t5 VALUES('a b c d', 'e f g h i j');
139 INSERT INTO t5 VALUES('', 'a');
140 INSERT INTO t5 VALUES('a', '');
141 }
142 do_execsql_test 5.2 {
143 SELECT rowid, fts5_test_columnsize(t5) FROM t5 WHERE t5 MATCH 'a'
144 ORDER BY rowid DESC;
145 } {
146 3 {1 0}
147 2 {0 1}
148 1 {4 6}
149 }
150
151 do_execsql_test 5.3 {
152 SELECT rowid, fts5_test_columntext(t5) FROM t5 WHERE t5 MATCH 'a'
153 ORDER BY rowid DESC;
154 } {
155 3 {a {}}
156 2 {{} a}
157 1 {{a b c d} {e f g h i j}}
158 }
159
160 do_execsql_test 5.4 {
161 SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a'
162 ORDER BY rowid DESC;
163 } {
164 3 {5 7}
165 2 {5 7}
166 1 {5 7}
167 }
168
169 do_execsql_test 5.5 {
170 INSERT INTO t5 VALUES('x y z', 'v w x y z');
171 SELECT rowid, fts5_test_columntotalsize(t5) FROM t5 WHERE t5 MATCH 'a'
172 ORDER BY rowid DESC;
173 } {
174 3 {8 12}
175 2 {8 12}
176 1 {8 12}
177 }
178
179 #-------------------------------------------------------------------------
180 # Test the xTokenize() API
181 #
182 reset_db
183 fts5_aux_test_functions db
184 do_execsql_test 6.1 {
185 CREATE VIRTUAL TABLE t6 USING fts5(x, y);
186 INSERT INTO t6 VALUES('There are more', 'things in heaven and earth');
187 INSERT INTO t6 VALUES(', Horatio, Than are', 'dreamt of in your philosophy.');
188 }
189
190 do_execsql_test 6.2 {
191 SELECT rowid, fts5_test_tokenize(t6) FROM t6 WHERE t6 MATCH 't*'
192 } {
193 1 {{there are more} {things in heaven and earth}}
194 2 {{horatio than are} {dreamt of in your philosophy}}
195 }
196
197 #-------------------------------------------------------------------------
198 # Test the xQueryPhrase() API
199 #
200 reset_db
201 fts5_aux_test_functions db
202 do_execsql_test 7.1 {
203 CREATE VIRTUAL TABLE t7 USING fts5(x, y);
204 }
205 do_test 7.2 {
206 foreach {x y} {
207 {q i b w s a a e l o} {i b z a l f p t e u}
208 {b a z t a l o x d i} {b p a d b f h d w y}
209 {z m h n p p u i e g} {v h d v b x j j c z}
210 {a g i m v a u c b i} {p k s o t l r t b m}
211 {v v c j o d a s c p} {f f v o k p o f o g}
212 } {
213 execsql {INSERT INTO t7 VALUES($x, $y)}
214 }
215 execsql { SELECT count(*) FROM t7 }
216 } {5}
217
218 foreach {tn q res} {
219 1 a {{4 2}}
220 2 b {{3 4}}
221 3 c {{2 1}}
222 4 d {{2 2}}
223 5 {a AND b} {{4 2} {3 4}}
224 6 {a OR b OR c OR d} {{4 2} {3 4} {2 1} {2 2}}
225 } {
226 do_execsql_test 7.3.$tn {
227 SELECT fts5_test_queryphrase(t7) FROM t7 WHERE t7 MATCH $q LIMIT 1
228 } [list $res]
229 }
230
231 do_execsql_test 7.4 {
232 SELECT fts5_test_rowcount(t7) FROM t7 WHERE t7 MATCH 'a';
233 } {5 5 5 5}
234
235 #do_execsql_test 7.4 {
236 # SELECT rowid, bm25debug(t7) FROM t7 WHERE t7 MATCH 'a';
237 #} {5 5 5 5}
238 #
239
240 #-------------------------------------------------------------------------
241 #
242 do_test 8.1 {
243 execsql { CREATE VIRTUAL TABLE t8 USING fts5(x, y) }
244 foreach {rowid x y} {
245 0 {A o} {o o o C o o o o o o o o}
246 1 {o o B} {o o o C C o o o o o o o}
247 2 {A o o} {o o o o D D o o o o o o}
248 3 {o B} {o o o o o D o o o o o o}
249 4 {E o G} {H o o o o o o o o o o o}
250 5 {F o G} {I o J o o o o o o o o o}
251 6 {E o o} {H o J o o o o o o o o o}
252 7 {o o o} {o o o o o o o o o o o o}
253 9 {o o o} {o o o o o o o o o o o o}
254 } {
255 execsql { INSERT INTO t8(rowid, x, y) VALUES($rowid, $x, $y) }
256 }
257 } {}
258
259 foreach {tn q res} {
260 1 {a} {0 2}
261 2 {b} {3 1}
262 3 {c} {1 0}
263 4 {d} {2 3}
264 5 {g AND (e OR f)} {5 4}
265 6 {j AND (h OR i)} {5 6}
266 } {
267 do_execsql_test 8.2.$tn.1 {
268 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8);
269 } $res
270
271 do_execsql_test 8.2.$tn.2 {
272 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank;
273 } $res
274
275 do_execsql_test 8.2.$tn.3 {
276 SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank;
277 } $res
278 }
279
280 #-------------------------------------------------------------------------
281 # Test xPhraseCount() for some different queries.
282 #
283 do_test 9.1 {
284 execsql { CREATE VIRTUAL TABLE t9 USING fts5(x) }
285 foreach x {
286 "a b c" "d e f"
287 } {
288 execsql { INSERT INTO t9 VALUES($x) }
289 }
290 } {}
291
292 foreach {tn q cnt} {
293 1 {a AND b} 2
294 2 {a OR b} 2
295 3 {a OR b OR c} 3
296 4 {NEAR(a b)} 2
297 } {
298 do_execsql_test 9.2.$tn {
299 SELECT fts5_test_phrasecount(t9) FROM t9 WHERE t9 MATCH $q LIMIT 1
300 } $cnt
301 }
302
303 finish_test
304
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698