/ Check-in [3ee7b5a9]
Login

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

Overview
Comment:Fix the bm25() function so that it multiplies scores by -1 before returning them. This means better matches have a lower numerical score, so "ORDER BY rank" (not "ORDER BY rank DESC") does what you want.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts5
Files: files | file ages | folders
SHA1: 3ee7b5a9f987c269251620ae7cc0fc7876b58ee5
User & Date: dan 2015-03-07 11:50:31
Context
2015-03-07
15:46
Fix some compiler warnings caused by signed/unsigned pointer conversions. check-in: cccee7b5 user: dan tags: fts5
11:50
Fix the bm25() function so that it multiplies scores by -1 before returning them. This means better matches have a lower numerical score, so "ORDER BY rank" (not "ORDER BY rank DESC") does what you want. check-in: 3ee7b5a9 user: dan tags: fts5
2015-03-04
08:29
Fix a couple of build problems. check-in: a5d5468c user: dan tags: fts5
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5.h.

    96     96   ** xTokenize:
    97     97   **   Tokenize text using the tokenizer belonging to the FTS5 table.
    98     98   **
    99     99   ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
   100    100   **   This API function is used to query the FTS table for phrase iPhrase
   101    101   **   of the current query. Specifically, a query equivalent to:
   102    102   **
   103         -**       ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid DESC
          103  +**       ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
   104    104   **
   105    105   **   with $p set to a phrase equivalent to the phrase iPhrase of the
   106    106   **   current query is executed. For each row visited, the callback function
   107    107   **   passed as the fourth argument is invoked. The context and API objects 
   108    108   **   passed to the callback function may be used to access the properties of
   109    109   **   each matched row. Invoking Api.xUserData() returns a copy of the pointer
   110    110   **   passed as the third argument to pUserData.

Changes to ext/fts5/fts5_aux.c.

   516    516         ( aFreq[i] + k1 * (1 - b + b * D / pData->avgdl) )
   517    517       );
   518    518     }
   519    519     
   520    520     /* If no error has occurred, return the calculated score. Otherwise,
   521    521     ** throw an SQL exception.  */
   522    522     if( rc==SQLITE_OK ){
   523         -    sqlite3_result_double(pCtx, score);
          523  +    sqlite3_result_double(pCtx, -1.0 * score);
   524    524     }else{
   525    525       sqlite3_result_error_code(pCtx, rc);
   526    526     }
   527    527   }
   528    528   
   529    529   int sqlite3Fts5AuxInit(fts5_api *pApi){
   530    530     struct Builtin {

Changes to ext/fts5/fts5_hash.c.

    65     65   
    66     66     int iCol;                       /* Column of last value written */
    67     67     int iPos;                       /* Position of last value written */
    68     68     i64 iRowid;                     /* Rowid of last value written */
    69     69     char zKey[0];                   /* Nul-terminated entry key */
    70     70   };
    71     71   
    72         -/*
    73         -** Format value iVal as a 4-byte varint and write it to buffer a[]. 4 bytes
    74         -** are used even if the value could fit in a smaller amount of space. 
    75         -*/
    76         -static void fts5Put4ByteVarint(u8 *a, int iVal){
    77         -  a[0] = (0x80 | (u8)(iVal >> 21));
    78         -  a[1] = (0x80 | (u8)(iVal >> 14));
    79         -  a[2] = (0x80 | (u8)(iVal >>  7));
    80         -  a[3] = (0x7F & (u8)(iVal));
    81         -}
    82         -
    83         -static int fts5Get4ByteVarint(u8 *a, int *pnVarint){
    84         -  int iRet = ((int)(a[0] & 0x7F) << 21) + ((int)(a[1] & 0x7F) << 14)
    85         -       + ((int)(a[2] & 0x7F) <<  7) + ((int)(a[3]));
    86         -  *pnVarint = (
    87         -      (iRet & 0xFFFFFF80)==0 ? 1 : 
    88         -      (iRet & 0xFFFFC000)==0 ? 2 :
    89         -      (iRet & 0xFFE00000)==0 ? 3 : 4
    90         -  );
    91         -  return iRet;
    92         -}
    93         -
    94     72   /*
    95     73   ** Allocate a new hash table.
    96     74   */
    97     75   int sqlite3Fts5HashNew(Fts5Hash **ppNew, int *pnByte){
    98     76     int rc = SQLITE_OK;
    99     77     Fts5Hash *pNew;
   100     78   

Changes to ext/fts5/test/fts5ae.test.

   261    261     2 {b} {3 1}
   262    262     3 {c} {1 0}
   263    263     4 {d} {2 3}
   264    264     5 {g AND (e OR f)} {5 4}
   265    265     6 {j AND (h OR i)} {5 6}
   266    266   } {
   267    267     do_execsql_test 8.2.$tn.1 {
   268         -    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8) DESC;
          268  +    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8);
   269    269     } $res
   270    270   
   271    271     do_execsql_test 8.2.$tn.2 {
   272         -    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank DESC;
          272  +    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank;
   273    273     } $res
   274    274   
   275    275     do_execsql_test 8.2.$tn.3 {
   276         -    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank DESC;
          276  +    SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank;
   277    277     } $res
   278    278   }
   279    279   
   280    280   finish_test
   281    281