]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Have the fts5 snippet() function avoid favouring snippets that begin with sentences...
authordan <dan@noemail.net>
Fri, 19 Aug 2016 14:25:38 +0000 (14:25 +0000)
committerdan <dan@noemail.net>
Fri, 19 Aug 2016 14:25:38 +0000 (14:25 +0000)
FossilOrigin-Name: d8180af2adfc101dfce95a0498b5cd7b30643b30

ext/fts5/fts5_aux.c
manifest
manifest.uuid

index ca55fd6b0156eae809d718e7eb30165fec7f3071..8efe05968e78ae77484a47b0e7afa5644d722a0b 100644 (file)
@@ -422,39 +422,46 @@ static void fts5SnippetFunction(
       rc = pApi->xColumnSize(pFts, i, &nDocsize);
       if( rc!=SQLITE_OK ) break;
 
-      for(ii=0; rc==SQLITE_OK && ii<sFinder.nFirst; ii++){
-        int nScore;
-        memset(aSeen, 0, nPhrase);
-        rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, 
-            sFinder.aFirst[ii], nToken, &nScore, 0
-        );
-
-        /* Bonus of 100 points for starting at the start of a sentence */
-        nScore += 100;            
-
-        if( rc==SQLITE_OK && nScore>nBestScore ){
-          nBestScore = nScore;
-          iBestCol = i;
-          iBestStart = sFinder.aFirst[ii];
-          nColSize = nDocsize;
-        }
-      }
-
       for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
         int ip, ic, io;
+        int iAdj;
         int nScore;
+        int jj;
+
         rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
         if( ic!=i || rc!=SQLITE_OK ) continue;
         memset(aSeen, 0, nPhrase);
         rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
-            io, nToken, &nScore, &io
+            io, nToken, &nScore, &iAdj
         );
         if( rc==SQLITE_OK && nScore>nBestScore ){
           nBestScore = nScore;
           iBestCol = i;
-          iBestStart = io;
+          iBestStart = iAdj;
           nColSize = nDocsize;
         }
+
+        if( rc==SQLITE_OK && sFinder.nFirst ){
+          for(jj=0; jj<(sFinder.nFirst-1); jj++){
+            if( sFinder.aFirst[jj+1]>io ) break;
+          }
+
+          if( sFinder.aFirst[jj]<io ){
+            int nScore;
+            memset(aSeen, 0, nPhrase);
+            rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, 
+              sFinder.aFirst[jj], nToken, &nScore, 0
+            );
+
+            nScore += (sFinder.aFirst[jj]==0 ? 120 : 100);
+            if( rc==SQLITE_OK && nScore>nBestScore ){
+              nBestScore = nScore;
+              iBestCol = i;
+              iBestStart = sFinder.aFirst[jj];
+              nColSize = nDocsize;
+            }
+          }
+        }
       }
     }
   }
index 9749b2bf53b7468e6440e6e3171207e343f6b2c6..f261342285f1afc7d22e5e7cf3a6ab062f19c506 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Adjust\ssome\stests\sto\saccount\sfor\srecent\schanges\sto\sthe\sfts5\ssnippet\sfunction.
-D 2016-08-18T14:47:48.448
+C Have\sthe\sfts5\ssnippet()\sfunction\savoid\sfavouring\ssnippets\sthat\sbegin\swith\ssentences\sthat\sdo\snot\scontain\ssearch\sterms.\sAdd\san\sextra\sbias\sin\sfavour\sof\sthe\sfirst\ssentence\sin\sthe\sdocument.
+D 2016-08-19T14:25:38.928
 F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a
@@ -99,7 +99,7 @@ F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95
 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0
 F ext/fts5/fts5.h 62f3e33ceeb9a428db139f9c012186b371da1cc7
 F ext/fts5/fts5Int.h b2eda36e0f224365c8e23dc8f559311834f1c13f
-F ext/fts5/fts5_aux.c 5921bbef4c78b86159111335135837a867f1ff8a
+F ext/fts5/fts5_aux.c 26a2b7e5f02cdc6b7322b85f473e488de452a5be
 F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd
 F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857
 F ext/fts5/fts5_expr.c 1ee97156421919e497595bfa962bb88ad1665401
@@ -1510,7 +1510,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 60de159476edbd48dc363f7f77f09c32ea68422f
-R 8546174dc7a44b2b80755efe3cb03b8a
+P 184ecbe9c0c3280a22cdeda5c7836a7b280c3e1f
+R 1ef5a5b8d26eab21fbb58bf0464e61ed
 U dan
-Z b3f4b9f04ef4ae0622fcf2d28707aee5
+Z ed743fa5b6cead3848c470a1b5a47844
index eb9043217fcbadcde1fb05b2c3c167b8b4aa477f..c3129c10b98e1244c87810a1f76876376d729bac 100644 (file)
@@ -1 +1 @@
-184ecbe9c0c3280a22cdeda5c7836a7b280c3e1f
\ No newline at end of file
+d8180af2adfc101dfce95a0498b5cd7b30643b30
\ No newline at end of file