/ Hex Artifact Content
Login

Artifact 11dcebba31d822f7e99685b4ea2c2ae3ec0b16f1:


0000: 23 20 32 30 31 34 20 44 65 63 20 32 30 0a 23 0a  # 2014 Dec 20.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou give..#.#****
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 0a 23 0a 23 20 54 68 69 73 20 66 69 6c  ***.#.# This fil
0170: 65 20 66 6f 63 75 73 65 73 20 6f 6e 20 74 65 73  e focuses on tes
0180: 74 69 6e 67 20 71 75 65 72 69 65 73 20 74 68 61  ting queries tha
0190: 74 20 75 73 65 20 74 68 65 20 22 72 61 6e 6b 22  t use the "rank"
01a0: 20 63 6f 6c 75 6d 6e 2e 0a 23 0a 0a 73 6f 75 72   column..#..sour
01b0: 63 65 20 5b 66 69 6c 65 20 6a 6f 69 6e 20 5b 66  ce [file join [f
01c0: 69 6c 65 20 64 69 72 6e 61 6d 65 20 5b 69 6e 66  ile dirname [inf
01d0: 6f 20 73 63 72 69 70 74 5d 5d 20 66 74 73 35 5f  o script]] fts5_
01e0: 63 6f 6d 6d 6f 6e 2e 74 63 6c 5d 0a 73 65 74 20  common.tcl].set 
01f0: 74 65 73 74 70 72 65 66 69 78 20 66 74 73 35 72  testprefix fts5r
0200: 61 6e 6b 0a 0a 23 20 49 66 20 53 51 4c 49 54 45  ank..# If SQLITE
0210: 5f 45 4e 41 42 4c 45 5f 46 54 53 35 20 69 73 20  _ENABLE_FTS5 is 
0220: 64 65 66 69 6e 65 64 2c 20 6f 6d 69 74 20 74 68  defined, omit th
0230: 69 73 20 66 69 6c 65 2e 0a 69 66 63 61 70 61 62  is file..ifcapab
0240: 6c 65 20 21 66 74 73 35 20 7b 0a 20 20 66 69 6e  le !fts5 {.  fin
0250: 69 73 68 5f 74 65 73 74 0a 20 20 72 65 74 75 72  ish_test.  retur
0260: 6e 0a 7d 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  n.}...#---------
0270: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0280: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0290: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02b0: 0a 23 20 22 4f 52 44 45 52 20 42 59 20 72 61 6e  .# "ORDER BY ran
02c0: 6b 22 20 2b 20 68 69 67 68 6c 69 67 68 74 28 29  k" + highlight()
02d0: 20 2b 20 6c 61 72 67 65 20 70 6f 73 6c 69 73 74   + large poslist
02e0: 73 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  s..#.do_execsql_
02f0: 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 43 52 45  test 1.0 {.  CRE
0300: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
0310: 45 20 78 79 7a 20 55 53 49 4e 47 20 66 74 73 35  E xyz USING fts5
0320: 28 7a 29 3b 0a 7d 0a 64 6f 5f 74 65 73 74 20 31  (z);.}.do_test 1
0330: 2e 31 20 7b 0a 20 20 73 65 74 20 64 6f 63 20 5b  .1 {.  set doc [
0340: 73 74 72 69 6e 67 20 74 72 69 6d 20 5b 73 74 72  string trim [str
0350: 69 6e 67 20 72 65 70 65 61 74 20 22 78 20 79 20  ing repeat "x y 
0360: 22 20 35 30 30 5d 5d 0a 20 20 65 78 65 63 73 71  " 500]].  execsq
0370: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
0380: 78 79 7a 20 56 41 4c 55 45 53 28 24 64 6f 63 29  xyz VALUES($doc)
0390: 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 65 78 65 63 73   }.} {}.do_execs
03a0: 71 6c 5f 74 65 73 74 20 31 2e 32 20 7b 0a 20 20  ql_test 1.2 {.  
03b0: 53 45 4c 45 43 54 20 68 69 67 68 6c 69 67 68 74  SELECT highlight
03c0: 28 78 79 7a 2c 20 30 2c 20 27 5b 27 2c 20 27 5d  (xyz, 0, '[', ']
03d0: 27 29 20 46 52 4f 4d 20 78 79 7a 20 57 48 45 52  ') FROM xyz WHER
03e0: 45 20 78 79 7a 20 4d 41 54 43 48 20 27 78 27 20  E xyz MATCH 'x' 
03f0: 4f 52 44 45 52 20 42 59 20 72 61 6e 6b 0a 7d 20  ORDER BY rank.} 
0400: 5b 6c 69 73 74 20 5b 73 74 72 69 6e 67 20 6d 61  [list [string ma
0410: 70 20 7b 78 20 5b 78 5d 7d 20 24 64 6f 63 5d 5d  p {x [x]} $doc]]
0420: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
0430: 74 20 31 2e 33 20 7b 0a 20 20 53 45 4c 45 43 54  t 1.3 {.  SELECT
0440: 20 68 69 67 68 6c 69 67 68 74 28 78 79 7a 2c 20   highlight(xyz, 
0450: 30 2c 20 27 5b 27 2c 20 27 5d 27 29 20 46 52 4f  0, '[', ']') FRO
0460: 4d 20 78 79 7a 0a 20 20 57 48 45 52 45 20 78 79  M xyz.  WHERE xy
0470: 7a 20 4d 41 54 43 48 20 27 78 20 41 4e 44 20 79  z MATCH 'x AND y
0480: 27 20 4f 52 44 45 52 20 42 59 20 72 61 6e 6b 0a  ' ORDER BY rank.
0490: 7d 20 5b 6c 69 73 74 20 5b 73 74 72 69 6e 67 20  } [list [string 
04a0: 6d 61 70 20 7b 78 20 5b 78 5d 20 79 20 5b 79 5d  map {x [x] y [y]
04b0: 7d 20 24 64 6f 63 5d 5d 0a 0a 66 69 6e 69 73 68  } $doc]]..finish
04c0: 5f 74 65 73 74 0a 0a                             _test..