/ Check-in [89d63682]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the edit_cost_table= command to the spellfix1 virtual table, permitting the edit distance cost table to be changed at runtime.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 89d6368250f9ba2f49e930bbe5524f3da615ce70
User & Date: drh 2013-02-19 11:51:27
Context
2013-02-19
18:34
Truncate over-length source lines in sqliteInt.h to 80 characters or less. check-in: d71abab0 user: drh tags: trunk
11:51
Add the edit_cost_table= command to the spellfix1 virtual table, permitting the edit distance cost table to be changed at runtime. check-in: 89d63682 user: drh tags: trunk
2013-02-16
02:41
Fix an unsafe VM register deallocation. check-in: cfba2c8d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_spellfix.c.

  2676   2676           return SQLITE_CONSTRAINT_NOTNULL;
  2677   2677         }
  2678   2678         if( strcmp(zCmd,"reset")==0 ){
  2679   2679           /* Reset the  edit cost table (if there is one). */
  2680   2680           editDist3ConfigDelete(p->pConfig3);
  2681   2681           p->pConfig3 = 0;
  2682   2682           return SQLITE_OK;
         2683  +      }
         2684  +      if( memcmp(zCmd,"edit_cost_table=",16)==0 ){
         2685  +        editDist3ConfigDelete(p->pConfig3);
         2686  +        p->pConfig3 = 0;
         2687  +        sqlite3_free(p->zCostTable);
         2688  +        p->zCostTable = spellfix1Dequote(zCmd+16);
         2689  +        if( p->zCostTable==0 ) return SQLITE_NOMEM;
         2690  +        if( p->zCostTable[0]==0 || sqlite3_stricmp(p->zCostTable,"null")==0 ){
         2691  +          sqlite3_free(p->zCostTable);
         2692  +          p->zCostTable = 0;
         2693  +        }
         2694  +        return SQLITE_OK;
  2683   2695         }
  2684   2696         pVTab->zErrMsg = sqlite3_mprintf("unknown value for %s.command: \"%w\"",
  2685   2697                                          p->zTableName, zCmd);
  2686   2698         return SQLITE_ERROR;
  2687   2699       }
  2688   2700       if( iRank<1 ) iRank = 1;
  2689   2701       if( zSoundslike ){

Changes to test/spellfix.test.

   132    132   
   133    133   do_test 3.2 {
   134    134     foreach w $vocab {
   135    135       execsql { INSERT INTO t3(word) VALUES($w) }
   136    136     }
   137    137   } {}
   138    138   
   139         -breakpoint
   140    139   foreach {tn word res} {
   141    140     1   kos*     {kosher 3 kiosk 4 kudo 2 kiss 3 kissed 3}
   142    141     2   kellj*   {killjoy 5 kill 4 killed 4 killer 4 killers 4}
   143    142     3   kellj    {kill 4 kills 5 killjoy 7 keel 4 killed 6}
   144    143   } {
   145         -  do_execsql_test 1.2.$tn {
          144  +  do_execsql_test 3.2.$tn {
   146    145       SELECT word, matchlen FROM t3 WHERE word MATCH $word
   147    146        ORDER BY score, word LIMIT 5
   148    147     } $res
   149         -} 
          148  +}
          149  +
          150  +do_execsql_test 4.0 {
          151  +  INSERT INTO t3(command) VALUES('edit_cost_table=NULL');
          152  +}
          153  +foreach {tn word res} {
          154  +  1   kosher     {kosher 0 kisser 51 kissers 76 kissed 126 kisses 126}
          155  +  2   kellj      {keels 60 killjoy 68 kills 80 keel 120 kill 125}
          156  +  3   kashar     {kosher 80 kisser 91 kissers 116 kissed 166 kisses 166}
          157  +} {
          158  +  do_execsql_test 4.1.$tn {
          159  +    SELECT word, distance FROM t3 WHERE word MATCH $word
          160  +     ORDER BY score, word LIMIT 5
          161  +  } $res
          162  +}
          163  +do_execsql_test 5.0 {
          164  +  CREATE TABLE costs2(iLang, cFrom, cTo, iCost);
          165  +  INSERT INTO costs2 VALUES(0, 'a', 'o', 1);
          166  +  INSERT INTO costs2 VALUES(0, 'e', 'o', 4);
          167  +  INSERT INTO costs2 VALUES(0, 'i', 'o', 8);
          168  +  INSERT INTO costs2 VALUES(0, 'u', 'o', 16);
          169  +  INSERT INTO t3(command) VALUES('edit_cost_table="costs2"');
          170  +}
          171  +
          172  +foreach {tn word res} {
          173  +  1   kasher     {kosher 1}
          174  +  2   kesher     {kosher 4}
          175  +  3   kisher     {kosher 8}
          176  +  4   kosher     {kosher 0}
          177  +  5   kusher     {kosher 16}
          178  +} {
          179  +  do_execsql_test 5.1.$tn {
          180  +    SELECT word, distance FROM t3 WHERE word MATCH $word
          181  +     ORDER BY score, word LIMIT 1
          182  +  } $res
          183  +}
          184  +
          185  +
   150    186   
   151    187   finish_test