Fix a bug in the fts5 snippet function causing it to return text containing zero phrase instances.

FossilOrigin-Name: b174ed2bde43a1872374ce18b85ac9f067e86fbb
This commit is contained in:
dan 2016-08-24 18:50:47 +00:00
parent 783e778f38
commit 37ff4d4c77
4 changed files with 21 additions and 10 deletions

View File

@ -331,6 +331,7 @@ static int fts5SnippetScore(
int iFirst = -1;
int nInst;
int nScore = 0;
int iLast = 0;
rc = pApi->xInstCount(pFts, &nInst);
for(i=0; i<nInst && rc==SQLITE_OK; i++){
@ -339,14 +340,13 @@ static int fts5SnippetScore(
nScore += (aSeen[ip] ? 1 : 1000);
aSeen[ip] = 1;
if( iFirst<0 ) iFirst = iOff;
iLast = iOff + pApi->xPhraseSize(pFts, ip);
}
}
*pnScore = nScore;
if( piPos ){
int iLast = iOff + pApi->xPhraseSize(pFts, ip);
int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
if( iAdj<0 ) iAdj = 0;
*piPos = iAdj;

View File

@ -164,6 +164,17 @@ do_execsql_test 4.0 {
{1 2 3 4 5...}
}
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE p1 USING fts5(a, b);
INSERT INTO p1 VALUES(
'x a a a a a a a a a a',
'a a a a a a a a a a a a a a a a a a a x'
);
}
do_execsql_test 5.1 {
SELECT snippet(p1, 0, '[', ']', '...', 6) FROM p1('x');
} {{[x] a a a a a...}}
} ;# foreach_detail_mode
finish_test

View File

@ -1,5 +1,5 @@
C Fix\sother\sminor\sproblems\swith\sthe\sfts5\ssnippet()\sfunction.
D 2016-08-20T17:23:45.034
C Fix\sa\sbug\sin\sthe\sfts5\ssnippet\sfunction\scausing\sit\sto\sreturn\stext\scontaining\szero\sphrase\sinstances.
D 2016-08-24T18:50:47.193
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 13246759ce03614a3b214894fa4b0f76891e97c0
F ext/fts5/fts5_aux.c 2f20784a344701d4c72986e2e692062dd47d568c
F ext/fts5/fts5_buffer.c 4c1502d4c956cd092c89ce4480867f9d8bf325cd
F ext/fts5/fts5_config.c 5af9c360e99669d29f06492c370892394aba0857
F ext/fts5/fts5_expr.c 1ee97156421919e497595bfa962bb88ad1665401
@ -122,7 +122,7 @@ F ext/fts5/test/fts5ab.test 30325a89453280160106be411bba3acf138e6d1b
F ext/fts5/test/fts5ac.test 55cad4275a1f5acabfe14d8442a8046b47e49e5f
F ext/fts5/test/fts5ad.test 36995f0586f30f5602074e012b9224c71ec5171c
F ext/fts5/test/fts5ae.test 612dcb51f4069226791ff14c17dbfb3138c56f20
F ext/fts5/test/fts5af.test b21abd9455c7351a9ef872b650d16f9dd8db2c49
F ext/fts5/test/fts5af.test c92825778ed2adc80014832762c056bbe968ef88
F ext/fts5/test/fts5ag.test 27180de76c03036be75ee80b93d8c5f540014071
F ext/fts5/test/fts5ah.test dfb7897711dbcda1dacb038aec310daca139fcf5
F ext/fts5/test/fts5ai.test 3909d0b949b2afcaae4d5795cd79153da75381df
@ -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 b10e31dce8e590e1ba30f512374a8c16656bcc72
R adacbf86d42eaec5a7639c5010230497
P b56b2a85cf377686727f3929208ede43f797cf76
R d95861b85eb0fcd438ce646b06ec5daf
U dan
Z 520e1a56589636baad586098a109d286
Z 1e5d85bd62c3d7d96772d546309a0d7d

View File

@ -1 +1 @@
b56b2a85cf377686727f3929208ede43f797cf76
b174ed2bde43a1872374ce18b85ac9f067e86fbb