modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/fts5/test/fts5synonym2.test (about)

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