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.

FossilOrigin-Name: 3ee7b5a9f987c269251620ae7cc0fc7876b58ee5
This commit is contained in:
dan
2015-03-07 11:50:31 +00:00
parent 47c467c80e
commit 6f876c339d
6 changed files with 15 additions and 37 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ typedef void (*fts5_extension_function)(
** This API function is used to query the FTS table for phrase iPhrase
** of the current query. Specifically, a query equivalent to:
**
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid DESC
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
**
** with $p set to a phrase equivalent to the phrase iPhrase of the
** current query is executed. For each row visited, the callback function
+1 -1
View File
@@ -520,7 +520,7 @@ static void fts5Bm25Function(
/* If no error has occurred, return the calculated score. Otherwise,
** throw an SQL exception. */
if( rc==SQLITE_OK ){
sqlite3_result_double(pCtx, score);
sqlite3_result_double(pCtx, -1.0 * score);
}else{
sqlite3_result_error_code(pCtx, rc);
}
-22
View File
@@ -69,28 +69,6 @@ struct Fts5HashEntry {
char zKey[0]; /* Nul-terminated entry key */
};
/*
** Format value iVal as a 4-byte varint and write it to buffer a[]. 4 bytes
** are used even if the value could fit in a smaller amount of space.
*/
static void fts5Put4ByteVarint(u8 *a, int iVal){
a[0] = (0x80 | (u8)(iVal >> 21));
a[1] = (0x80 | (u8)(iVal >> 14));
a[2] = (0x80 | (u8)(iVal >> 7));
a[3] = (0x7F & (u8)(iVal));
}
static int fts5Get4ByteVarint(u8 *a, int *pnVarint){
int iRet = ((int)(a[0] & 0x7F) << 21) + ((int)(a[1] & 0x7F) << 14)
+ ((int)(a[2] & 0x7F) << 7) + ((int)(a[3]));
*pnVarint = (
(iRet & 0xFFFFFF80)==0 ? 1 :
(iRet & 0xFFFFC000)==0 ? 2 :
(iRet & 0xFFE00000)==0 ? 3 : 4
);
return iRet;
}
/*
** Allocate a new hash table.
*/
+3 -3
View File
@@ -265,15 +265,15 @@ foreach {tn q res} {
6 {j AND (h OR i)} {5 6}
} {
do_execsql_test 8.2.$tn.1 {
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8) DESC;
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY bm25(t8);
} $res
do_execsql_test 8.2.$tn.2 {
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank DESC;
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY +rank;
} $res
do_execsql_test 8.2.$tn.3 {
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank DESC;
SELECT rowid FROM t8 WHERE t8 MATCH $q ORDER BY rank;
} $res
}
+9 -9
View File
@@ -1,5 +1,5 @@
C Fix\sa\scouple\sof\sbuild\sproblems.
D 2015-03-04T08:29:24.833
C Fix\sthe\sbm25()\sfunction\sso\sthat\sit\smultiplies\sscores\sby\s-1\sbefore\sreturning\sthem.\sThis\smeans\sbetter\smatches\shave\sa\slower\snumerical\sscore,\sso\s"ORDER\sBY\srank"\s(not\s"ORDER\sBY\srank\sDESC")\sdoes\swhat\syou\swant.
D 2015-03-07T11:50:31.532
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -105,13 +105,13 @@ F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7
F ext/fts3/unicode/mkunicode.tcl 159c1194da0bc72f51b3c2eb71022568006dc5ad
F ext/fts5/extract_api_docs.tcl 55a6d648d516f35d9a1e580ac00de27154e1904a
F ext/fts5/fts5.c 1eb8ca073be5222c43e4eee5408764c2cbb4200b
F ext/fts5/fts5.h f931954065693898d26c51f23f1d27200184a69a
F ext/fts5/fts5.h 24a2cc35b5e76eec57b37ba48c12d9d2cb522b3a
F ext/fts5/fts5Int.h 5c8efea3d0a1ccc70194225f8c402a1732ed5ad5
F ext/fts5/fts5_aux.c c64e56b08c5be52fa688c078259cf903b164937a
F ext/fts5/fts5_aux.c fcea18b1a2a3f95a498b52aba2983557d7678a22
F ext/fts5/fts5_buffer.c 29f79841bf6eef5220eef41b122419b1bcb07b06
F ext/fts5/fts5_config.c 0847facc8914f57ea4452c43ce109200dc65e894
F ext/fts5/fts5_expr.c 5215137efab527577d36bdf9e44bfc2ec3e1be98
F ext/fts5/fts5_hash.c 6bc0f78cb3630c5ff27dbfb58847758e82c3d0ac
F ext/fts5/fts5_hash.c 13fcefb50a178c0f5086b88cdd781e26c413a3cb
F ext/fts5/fts5_index.c db8dc4cf906245dfd8a8d724695b60d6f22b7654
F ext/fts5/fts5_storage.c ac0f0937059c8d4f38a1f13aa5f2c2cd7edf3e0d
F ext/fts5/fts5_tcl.c 617b6bb96545be8d9045de6967c688cd9cd15541
@@ -124,7 +124,7 @@ F ext/fts5/test/fts5aa.test 065767c60ad301f77ad95f24369305e13347aa00
F ext/fts5/test/fts5ab.test 5da2e92a8047860b9e22b6fd3990549639d631b1
F ext/fts5/test/fts5ac.test 8b3c2938840da8f3f6a53b1324fb03e0bac12d1e
F ext/fts5/test/fts5ad.test 2141b0360dc4397bfed30f0b0d700fa64b44835d
F ext/fts5/test/fts5ae.test 347c96db06aab23ff00cf6a6b4064a8dbb182e42
F ext/fts5/test/fts5ae.test 9175201baf8c885fc1cbb2da11a0c61fd11224db
F ext/fts5/test/fts5af.test c2501ec2b61d6b179c305f5d2b8782ab3d4f832a
F ext/fts5/test/fts5ag.test ec3e119b728196620a31507ef503c455a7a73505
F ext/fts5/test/fts5ah.test 56b5a2599707621bf2fd1b5a00ddc0c0c1ffbf06
@@ -1284,7 +1284,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P a07dcca9ef3821a6719ef9dbbc8ed861fa005035
R c94fdf40731aa277dc09f612ab9d1498
P a5d5468c0509d129e198bf9432190ee07cedb7af
R aa671856811e9ea4e67d518a4616a999
U dan
Z 4c98d611f9675f463f695743f454384f
Z 4764624a6d652eca0ea7813e6c8b51f7
+1 -1
View File
@@ -1 +1 @@
a5d5468c0509d129e198bf9432190ee07cedb7af
3ee7b5a9f987c269251620ae7cc0fc7876b58ee5