fts5ag.test 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5ag
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. #-------------------------------------------------------------------------
  22. # This file attempts to verify that the extension APIs work with
  23. # "ORDER BY rank" queries. This is done by comparing the results of
  24. # the fts5_test() function when run with queries of the form:
  25. #
  26. # ... WHERE fts MATCH ? ORDER BY bm25(fts) [ASC|DESC]
  27. #
  28. # and
  29. #
  30. # ... WHERE fts MATCH ? ORDER BY rank [ASC|DESC]
  31. #
  32. foreach_detail_mode $testprefix {
  33. do_execsql_test 1.0 {
  34. CREATE VIRTUAL TABLE t1 USING fts5(x, y, z, detail=%DETAIL%);
  35. }
  36. do_test 1.1 {
  37. foreach {x y z} {
  38. {j s m y m r n l u k} {z k f u z g h s w g} {r n o s s b v n w w}
  39. {m v g n d x q r r s} {q t d a q a v l h j} {s k l f s i n v q v}
  40. {m f f d h h s o h a} {y e v r q i u m h d} {b c k q m z l z h n}
  41. {j e m v k p e c j m} {m p v z d x l n i a} {v p u p m t p q i f}
  42. {v r w l e e t d z p} {c s b w k m n k o u} {w g y f v w v w v p}
  43. {k d g o u j p z n o} {t g e q l z i g b j} {f i q q j y h b g h}
  44. {j s w x o t j b t m} {v a v v r t x c q a} {r t k x w u l h a g}
  45. {j y b i u d e m d w} {y s o j h i n a u p} {n a g b u c w e b m}
  46. {b c k s c w j p w b} {m o c o w o b d q q} {n t y o y z y r z e}
  47. {p n q l e l h z q c} {n s e i h c v b b u} {m p d i t a o o f f}
  48. {k c o n v e z l b m} {s m n i n s d e s u} {t a u e q d a o u c}
  49. {h d t o i a g b b p} {k x c i g f g b b k} {x f i v n a n n j i}
  50. {f z k r b u s k z e} {n z v z w l e r h t} {t i s v v a v p n s}
  51. {k f e c t z r e f d} {f m g r c w q k b v} {v y s y f r b f e f}
  52. {z r c t d q q h x b} {u c g z n z u v s s} {y t n f f x b f d x}
  53. {u n p n u t i m e j} {p j j d m f k p m z} {d o l v c o e a h w}
  54. {h o q w t f v i c y} {c q u n r z s l l q} {z x a q w s b w s y}
  55. {y m s x k i m n x c} {b i a n v h z n k a} {w l q p b h h g d y}
  56. {z v s j f p v l f w} {c s b i z e k i g c} {x b v d w j f e d z}
  57. {r k k j e o m k g b} {h b d c h m y b t u} {u j s h k z c u d y}
  58. {v h i v s y z i k l} {d t m w q w c a z p} {r s e s x v d w k b}
  59. {u r e q j y h o o s} {x x z r x y t f j s} {k n h x i i u e c v}
  60. {q l f d a p w l q o} {y z q w j o p b o v} {s u h z h f d f n l}
  61. {q o e o x x l g q i} {j g m h q q w c d b} {o m d h w a g b f n}
  62. {m x k t s s y l v a} {j x t c a u w b w g} {n f j b v x y p u t}
  63. {u w k a q b u w k w} {a h j u o w f s k p} {j o f s h y t j h g}
  64. {x v b l m t l m h l} {t p y i y i q b q a} {k o o z w a c h c f}
  65. {j g c d k w b d t v} {a k v c m a v h v p} {i c a i j g h l j h}
  66. {l m v l c z j b p b} {z p z f l n k i b a} {j v q k g i x g i b}
  67. {m c i w u z m i s z} {i z r f n l q z k w} {x n b p b q r g i z}
  68. {d g i o o x l f x d} {r t m f b n q y c b} {i u g k w x n m p o}
  69. {t o s i q d z x d t} {v a k s q z j c o o} {z f n n r l y w v v}
  70. {w k h d t l j g n n} {r z m v y b l n c u} {v b v s c l n k g v}
  71. {m a g r a b u u n z} {u y l h v w v k b f} {x l p g i s j f x v}
  72. {v s g x k z a k a r} {l t g v j q l k p l} {f h n a x t v s t y}
  73. {z u v u x p s j y t} {g b q e e g l n w g} {e n p j i g j f u r}
  74. {q z l t w o l m p e} {t s g h r p r o t z} {y b f a o n u m z g}
  75. {d t w n y b o g f o} {d a j e r l g g s h} {d z e l w q l t h f}
  76. {f l u w q v x j a h} {f n u l l d m h h w} {d x c c e r o d q j}
  77. {b y f q s q f u l g} {u z w l f d b i a g} {m v q b g u o z e z}
  78. {h z p t s e x i v m} {l h q m e o x x x j} {e e d n p r m g j f}
  79. {k h s g o n s d a x} {u d t t s j o v h a} {z r b a e u v o e s}
  80. {m b b g a f c p a t} {w c m j o d b l g e} {f p j p m o s y v j}
  81. {c r n h d w c a b l} {s g e u s d n j b g} {b o n a x a b x y l}
  82. {r h u x f c d z n o} {x y l g u m i i w d} {t f h b z v r s r g}
  83. {t i o r b v g g p a} {d x l u q k m o s u} {j f h t u n z u k m}
  84. {g j t y d c n j y g} {w e s k v c w i g t} {g a h r g v g h r o}
  85. {e j l a q j g i n h} {d z k c u p n u p p} {t u e e v z v r r g}
  86. {l j s g k j k h z l} {p v d a t x d e q u} {r l u z b m g k s j}
  87. {i e y d u x d i n l} {p f z k m m w p u l} {z l p m r q w n d a}
  88. } {
  89. execsql { INSERT INTO t1 VALUES($x, $y, $z) }
  90. }
  91. set {} {}
  92. } {}
  93. fts5_aux_test_functions db
  94. proc do_fts5ag_test {tn E} {
  95. set q1 {SELECT fts5_test_all(t1) FROM t1 WHERE t1 MATCH $E ORDER BY rank}
  96. set q2 {SELECT fts5_test_all(t1) FROM t1 WHERE t1 MATCH $E ORDER BY bm25(t1)}
  97. set res [execsql $q1]
  98. set expected [execsql $q2]
  99. uplevel [list do_test $tn.1 [list set {} $res] $expected]
  100. append q1 " DESC"
  101. append q2 " DESC"
  102. set res [execsql $q1]
  103. set expected [execsql $q2]
  104. uplevel [list do_test $tn.2 [list set {} $res] $expected]
  105. }
  106. foreach {tn expr} {
  107. 2.1 a
  108. 2.2 b
  109. 2.3 c
  110. 2.4 d
  111. 3.0 {a AND b}
  112. 3.1 {a OR b}
  113. 3.2 {b OR c AND d}
  114. } {
  115. do_fts5ag_test $tn $expr
  116. }
  117. if {[detail_is_full]} {
  118. foreach {tn expr} {
  119. 4.1 {"m m"}
  120. 4.2 {e + s}
  121. 4.3 {NEAR(c d)}
  122. } {
  123. do_fts5ag_test $tn $expr
  124. }
  125. }
  126. } ;# foreach_detail_mode
  127. finish_test