amatch1.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # 2013-09-30
  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 "approximate_match" virtual
  12. # table that is in the "amatch.c" extension.
  13. #
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # If SQLITE_ENABLE_FTS4 is defined, omit this file.
  18. ifcapable !fts3 {
  19. finish_test
  20. return
  21. }
  22. # Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
  23. # the complete text of the Book of Genesis.
  24. #
  25. source $testdir/genesis.tcl
  26. do_test amatch1-1.0 {
  27. db eval {
  28. CREATE VIRTUAL TABLE t1 USING fts4(words); --, tokenize porter);
  29. }
  30. fts_kjv_genesis
  31. db eval {
  32. INSERT INTO t1(t1) VALUES('optimize');
  33. CREATE VIRTUAL TABLE temp.t1aux USING fts4aux(main, t1);
  34. SELECT term FROM t1aux WHERE col=0 ORDER BY 1 LIMIT 5
  35. }
  36. } {a abated abel abelmizraim abidah}
  37. do_test amatch1-1.1 {
  38. db eval {
  39. SELECT term FROM t1aux WHERE term>'b' AND col=0 ORDER BY 1 LIMIT 5
  40. }
  41. } {baalhanan babel back backward bad}
  42. do_test amatch1-1.2 {
  43. db eval {
  44. SELECT term FROM t1aux WHERE term>'b' AND col=0 LIMIT 5
  45. }
  46. } {baalhanan babel back backward bad}
  47. # Load the amatch extension
  48. load_static_extension db amatch
  49. do_execsql_test amatch1-2.0 {
  50. CREATE TABLE costs(iLang, cFrom, cTo, Cost);
  51. INSERT INTO costs VALUES(0, '', '?', 100);
  52. INSERT INTO costs VALUES(0, '?', '', 100);
  53. INSERT INTO costs VALUES(0, '?', '?', 150);
  54. CREATE TABLE vocab(w TEXT UNIQUE);
  55. INSERT OR IGNORE INTO vocab SELECT term FROM t1aux;
  56. CREATE VIRTUAL TABLE t2 USING approximate_match(
  57. vocabulary_table=t1aux,
  58. vocabulary_word=term,
  59. edit_distances=costs
  60. );
  61. CREATE VIRTUAL TABLE t3 USING approximate_match(
  62. vocabulary_table=vocab,
  63. vocabulary_word=w,
  64. edit_distances=costs
  65. );
  66. CREATE VIRTUAL TABLE t4 USING approximate_match(
  67. vocabulary_table=vtemp,
  68. vocabulary_word=w,
  69. edit_distances=costs
  70. );
  71. } {}
  72. puts "Query against fts4aux: [time {
  73. do_execsql_test amatch1-2.1 {
  74. SELECT word, distance FROM t2
  75. WHERE word MATCH 'josxph' AND distance<300;
  76. } {joseph 150}} 1]"
  77. puts "Query against ordinary table: [time {
  78. do_execsql_test amatch1-2.2 {
  79. SELECT word, distance FROM t3
  80. WHERE word MATCH 'josxph' AND distance<300;
  81. } {joseph 150}} 1]"
  82. puts "Temp table initialized from fts4aux: [time {
  83. do_execsql_test amatch1-2.3a {
  84. CREATE TEMP TABLE vtemp(w TEXT UNIQUE);
  85. INSERT OR IGNORE INTO vtemp SELECT term FROM t1aux;
  86. } {}} 1]"
  87. puts "Query against temp table: [time {
  88. do_execsql_test amatch1-2.3b {
  89. SELECT word, distance FROM t4
  90. WHERE word MATCH 'josxph' AND distance<300;
  91. } {joseph 150}} 1]"
  92. do_execsql_test amatch1-2.11 {
  93. SELECT word, distance FROM t2
  94. WHERE word MATCH 'joxxph' AND distance<=300;
  95. } {joseph 300}
  96. do_execsql_test amatch1-2.12 {
  97. SELECT word, distance FROM t3
  98. WHERE word MATCH 'joxxph' AND distance<=300;
  99. } {joseph 300}
  100. do_execsql_test amatch1-2.21 {
  101. SELECT word, distance FROM t2
  102. WHERE word MATCH 'joxxph' AND distance<300;
  103. } {}
  104. do_execsql_test amatch1-2.22 {
  105. SELECT word, distance FROM t3
  106. WHERE word MATCH 'joxxph' AND distance<300;
  107. } {}
  108. finish_test