fts5synonym2.test 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # 2014 Dec 20
  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 focusing on custom tokenizers that support synonyms.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5synonym2
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. foreach tok {query document} {
  22. foreach_detail_mode $testprefix {
  23. fts5_tclnum_register db
  24. fts5_aux_test_functions db
  25. proc fts5_test_bothlist {cmd} {
  26. for {set i 0} {$i < [$cmd xPhraseCount]} {incr i} {
  27. set bFirst 1
  28. $cmd xPhraseColumnForeach $i c {
  29. lappend CL $i.$c
  30. if {$bFirst} { $cmd xPhraseForeach $i c o { lappend PL $i.$c.$o } }
  31. set bFirst 0
  32. }
  33. }
  34. list [sort_poslist $PL] $CL
  35. }
  36. sqlite3_fts5_create_function db fts5_test_bothlist fts5_test_bothlist
  37. proc fts5_rowid {cmd} { expr [$cmd xRowid] }
  38. sqlite3_fts5_create_function db fts5_rowid fts5_rowid
  39. do_execsql_test 1.$tok.0.1 "
  40. CREATE VIRTUAL TABLE ss USING fts5(a, b,
  41. tokenize='tclnum $tok', detail=%DETAIL%);
  42. INSERT INTO ss(ss, rank) VALUES('rank', 'fts5_rowid()');
  43. "
  44. do_execsql_test 1.$tok.0.2 {
  45. INSERT INTO ss VALUES('5 5 five seven 3 seven i', '2 1 5 0 two 1 i');
  46. INSERT INTO ss VALUES('six ix iii 7 i vii iii', 'one seven nine 4 9 1 vi');
  47. INSERT INTO ss VALUES('6 viii i five six zero seven', '5 v iii iv iv 3');
  48. INSERT INTO ss VALUES('9 ii six 8 1 6', 'six 4 iv iv 7');
  49. INSERT INTO ss VALUES('1 5 4 eight ii iv iii', 'nine 2 eight ix v vii');
  50. INSERT INTO ss VALUES('one 7 seven six 2 two', '1 2 four 7 4 3 4');
  51. INSERT INTO ss VALUES('eight iv 4 nine vii six 1', '5 6 v one zero 4');
  52. INSERT INTO ss VALUES('v 9 8 iii 4', '9 4 seven two vi vii');
  53. INSERT INTO ss VALUES('3 ix two 9 0 nine i', 'five ii nine two viii i five');
  54. INSERT INTO ss VALUES('six iii 9 two eight 2', 'nine i nine vii nine');
  55. INSERT INTO ss VALUES('6 three zero seven vii five', '8 vii ix 0 7 seven');
  56. INSERT INTO ss VALUES('8 vii 8 7 3 4', 'eight iii four viii nine iv three');
  57. INSERT INTO ss VALUES('4 v 7 two 0 one 8', 'vii 1 two five i zero 9');
  58. INSERT INTO ss VALUES('3 ii vii vi eight', '8 4 ix one three eight');
  59. INSERT INTO ss VALUES('iv eight seven 6 9 seven', 'one vi two five seven');
  60. INSERT INTO ss VALUES('i i 5 i v vii eight', '2 seven i 2 2 four');
  61. INSERT INTO ss VALUES('0 i iii nine 3 ix five', '0 eight iv 0 six 2');
  62. INSERT INTO ss VALUES('iv vii three 3 9 one 8', '2 ii 6 eight ii six six');
  63. INSERT INTO ss VALUES('eight one two nine six', '8 9 3 viii vi');
  64. INSERT INTO ss VALUES('one 0 four ii eight one 3', 'iii eight vi vi vi');
  65. INSERT INTO ss VALUES('4 0 eight 0 0', '1 four one vii seven ii');
  66. INSERT INTO ss VALUES('1 zero nine 2 2', 'viii iv two vi nine v iii');
  67. INSERT INTO ss VALUES('5 five viii four four vi', '8 five 7 vii 6 4');
  68. INSERT INTO ss VALUES('7 ix four 8 vii', 'nine three nine ii ix vii');
  69. INSERT INTO ss VALUES('nine iv v i 0 v', 'two iv vii six i ix 4');
  70. INSERT INTO ss VALUES('one v v one viii 3 8', '2 1 3 five iii');
  71. INSERT INTO ss VALUES('six ii 5 nine 4 viii seven', 'eight i ix ix 7 four');
  72. INSERT INTO ss VALUES('9 ii two seven three 7 0', 'six viii seven 7 five');
  73. INSERT INTO ss VALUES('five two 4 viii nine', '9 7 nine zero 1 two one');
  74. INSERT INTO ss VALUES('viii 8 iii i ii 8 3', '4 2 7 v 8 8');
  75. INSERT INTO ss VALUES('four vii 4 iii zero 0 vii', '3 viii iii zero 9 i');
  76. INSERT INTO ss VALUES('0 seven v five i five v', 'one 4 2 ix 9');
  77. INSERT INTO ss VALUES('two 5 two two ix 4 1', '3 nine ii v nine 3 five');
  78. INSERT INTO ss VALUES('five 5 7 4 6 vii', 'three 2 ix 2 8 6');
  79. INSERT INTO ss VALUES('six iii vi iv seven eight', '8 six 7 0 4');
  80. INSERT INTO ss VALUES('vi vi iv 3 0 one one', '9 6 eight ix iv');
  81. INSERT INTO ss VALUES('7 2 2 iii 0', '0 0 seven 1 nine');
  82. INSERT INTO ss VALUES('8 6 iv six ii', 'iv 6 3 4 ii five');
  83. INSERT INTO ss VALUES('0 two two seven ii', 'vii ix four 4 zero vi vi');
  84. INSERT INTO ss VALUES('2 one eight 8 9 7', 'vi 3 0 3 vii');
  85. INSERT INTO ss VALUES('iii ii ix iv three', 'vi i 6 1 two');
  86. INSERT INTO ss VALUES('eight four nine 8 seven', 'one three i nine iii one');
  87. INSERT INTO ss VALUES('iii seven five ix 8', 'ii 7 seven 0 four ii');
  88. INSERT INTO ss VALUES('four 0 1 5 two', 'iii 9 5 ii ii 2 4');
  89. INSERT INTO ss VALUES('iii nine four vi 8 five six', 'i i ii seven vi vii');
  90. INSERT INTO ss VALUES('eight vii eight six 3', 'i vii 1 six 9 vii');
  91. INSERT INTO ss VALUES('9 0 viii viii five', 'i 1 viii ix 3 4');
  92. INSERT INTO ss VALUES('three nine 5 nine viii four zero', 'ii i 1 5 2 viii');
  93. INSERT INTO ss VALUES('5 vii three 9 four', 'three five one 7 2 eight one');
  94. }
  95. foreach {tn expr} {
  96. 2.1 "one OR two OR three OR four"
  97. 1.1 "one" 1.2 "two" 1.3 "three" 1.4 "four"
  98. 1.5 "v" 1.6 "vi" 1.7 "vii" 1.8 "viii"
  99. 1.9 "9" 1.10 "0" 1.11 "1" 1.12 "2"
  100. 2.1 "one OR two OR three OR four"
  101. 2.2 "(one AND two) OR (three AND four)"
  102. 2.3 "(one AND two) OR (three AND four) NOT five"
  103. 2.4 "(one AND two) NOT 6"
  104. 3.1 "b:one AND a:two"
  105. 3.2 "b:one OR a:two"
  106. 3.3 "a:one OR b:1 OR {a b} : i"
  107. 4.1 "NEAR(one two, 2)"
  108. 4.2 "NEAR(one two three, 2)"
  109. 4.3 "NEAR(eight nine, 1) OR NEAR(six seven, 1)"
  110. 5.1 "one + two"
  111. 5.2 "1 + two"
  112. } {
  113. if {[fts5_expr_ok $expr ss]==0} {
  114. do_test 1.$tok.$tn.OMITTED { list } [list]
  115. continue
  116. }
  117. set res [fts5_query_data $expr ss ASC ::tclnum_syn]
  118. do_execsql_test 1.$tok.$tn.[llength $res].asc.1 {
  119. SELECT rowid, fts5_test_poslist2(ss), fts5_test_collist(ss) FROM ss($expr)
  120. } $res
  121. do_execsql_test 1.$tok.$tn.[llength $res].asc.2 {
  122. SELECT rowid, fts5_test_poslist(ss), fts5_test_collist(ss) FROM ss($expr)
  123. } $res
  124. do_execsql_test 1.$tok.$tn.[llength $res].asc.2 {
  125. SELECT rowid, fts5_test_poslist2(ss), fts5_test_collist(ss) FROM ss($expr)
  126. ORDER BY rank ASC
  127. } $res
  128. set res2 [list]
  129. foreach {a b c} $res { lappend res2 $a $c $b }
  130. do_execsql_test 1.$tok.$tn.[llength $res].asc.3 {
  131. SELECT rowid, fts5_test_collist(ss), fts5_test_poslist2(ss) FROM ss($expr)
  132. } $res2
  133. set res3 [list]
  134. foreach {a b c} $res { lappend res3 $a [list $b $c] }
  135. do_execsql_test 1.$tok.$tn.[llength $res].asc.3 {
  136. SELECT rowid, fts5_test_bothlist(ss) FROM ss($expr)
  137. } $res3
  138. }
  139. }
  140. }
  141. finish_test