fts5near.test 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 the NEAR operator.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5near
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. proc do_near_test {tn doc near res} {
  22. uplevel [list do_execsql_test $tn "
  23. DELETE FROM t1;
  24. INSERT INTO t1 VALUES('$doc');
  25. SELECT count(*) FROM t1 WHERE t1 MATCH '$near';
  26. " $res]
  27. }
  28. execsql {
  29. CREATE VIRTUAL TABLE t1 USING fts5(x, tokenize = "ascii tokenchars '.'")
  30. }
  31. do_near_test 1.1 ". . a . . . b . ." { NEAR(a b, 5) } 1
  32. do_near_test 1.2 ". . a . . . b . ." { NEAR(a b, 4) } 1
  33. do_near_test 1.3 ". . a . . . b . ." { NEAR(a b, 3) } 1
  34. do_near_test 1.4 ". . a . . . b . ." { NEAR(a b, 2) } 0
  35. do_near_test 1.5 ". . a . . . b . ." { NEAR(b a, 5) } 1
  36. do_near_test 1.6 ". . a . . . b . ." { NEAR(b a, 4) } 1
  37. do_near_test 1.7 ". . a . . . b . ." { NEAR(b a, 3) } 1
  38. do_near_test 1.8 ". . a . . . b . ." { NEAR(b a, 2) } 0
  39. do_near_test 1.9 ". a b . . . c . ." { NEAR("a b" c, 3) } 1
  40. do_near_test 1.10 ". a b . . . c . ." { NEAR("a b" c, 2) } 0
  41. do_near_test 1.11 ". a b . . . c . ." { NEAR(c "a b", 3) } 1
  42. do_near_test 1.12 ". a b . . . c . ." { NEAR(c "a b", 2) } 0
  43. do_near_test 1.13 ". a b . . . c d ." { NEAR(a+b c+d, 3) } 1
  44. do_near_test 1.14 ". a b . . . c d ." { NEAR(a+b c+d, 2) } 0
  45. do_near_test 1.15 ". a b . . . c d ." { NEAR(c+d a+b, 3) } 1
  46. do_near_test 1.16 ". a b . . . c d ." { NEAR(c+d a+b, 2) } 0
  47. do_near_test 1.17 ". a b . . . c d ." { NEAR(a b c d, 5) } 1
  48. do_near_test 1.18 ". a b . . . c d ." { NEAR(a b c d, 4) } 0
  49. do_near_test 1.19 ". a b . . . c d ." { NEAR(a+b c d, 4) } 1
  50. do_near_test 1.20 "a b c d e f g h i" { NEAR(b+c a+b+c+d i, 5) } 1
  51. do_near_test 1.21 "a b c d e f g h i" { NEAR(b+c a+b+c+d i, 4) } 0
  52. do_near_test 1.22 "a b c d e f g h i" { NEAR(a+b+c+d i b+c, 5) } 1
  53. do_near_test 1.23 "a b c d e f g h i" { NEAR(a+b+c+d i b+c, 4) } 0
  54. do_near_test 1.24 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 5) } 1
  55. do_near_test 1.25 "a b c d e f g h i" { NEAR(i a+b+c+d b+c, 4) } 0
  56. finish_test