return rc;
}
-static void fts3EvalFreeDeferredDoclist(Fts3Phrase *pPhrase){
+static void fts3EvalZeroPoslist(Fts3Phrase *pPhrase){
if( pPhrase->doclist.bFreeList ){
sqlite3_free(pPhrase->doclist.pList);
- pPhrase->doclist.pList = 0;
- pPhrase->doclist.nList = 0;
- pPhrase->doclist.bFreeList = 0;
}
+ pPhrase->doclist.pList = 0;
+ pPhrase->doclist.nList = 0;
+ pPhrase->doclist.bFreeList = 0;
}
static int fts3EvalNearTrim2(
char *pOut;
int res;
+ assert( pPhrase->doclist.pList );
+
p2 = pOut = pPhrase->doclist.pList;
res = fts3PoslistNearMerge(
&pOut, aTmp, nParam1, nParam2, paPoslist, &p2
fts3EvalNext(pCsr, pRight, pRc);
assert( *pRc!=SQLITE_OK || pRight->bStart );
}
- do {
- fts3EvalNext(pCsr, pLeft, pRc);
- if( pLeft->bEof ) break;
+
+ fts3EvalNext(pCsr, pLeft, pRc);
+ if( pLeft->bEof==0 ){
while( !*pRc
&& !pRight->bEof
&& DOCID_CMP(pLeft->iDocid, pRight->iDocid)>0
){
fts3EvalNext(pCsr, pRight, pRc);
}
- }while( !pRight->bEof && pRight->iDocid==pLeft->iDocid && !*pRc );
+ }
pExpr->iDocid = pLeft->iDocid;
pExpr->bEof = pLeft->bEof;
break;
default: {
Fts3Phrase *pPhrase = pExpr->pPhrase;
- fts3EvalFreeDeferredDoclist(pPhrase);
+ fts3EvalZeroPoslist(pPhrase);
*pRc = fts3EvalPhraseNext(pCsr, pPhrase, &pExpr->bEof);
pExpr->iDocid = pPhrase->doclist.iDocid;
break;
&& fts3EvalNearTest(pExpr, pRc)
);
- /* If this is a NEAR node and the NEAR expression does not match
- ** any rows, zero the doclist for all phrases involved in the NEAR.
- ** This is because the snippet(), offsets() and matchinfo() functions
- ** are not supposed to recognize any instances of phrases that are
- ** part of unmatched NEAR queries. For example if this expression:
+ /* If the NEAR expression does not match any rows, zero the doclist for
+ ** all phrases involved in the NEAR. This is because the snippet(),
+ ** offsets() and matchinfo() functions are not supposed to recognize
+ ** any instances of phrases that are part of unmatched NEAR queries.
+ ** For example if this expression:
**
** ... MATCH 'a OR (b NEAR c)'
**
** then any snippet() should ony highlight the "a" term, not the "b"
** (as "b" is part of a non-matching NEAR clause).
*/
- if( pExpr->eType==FTSQUERY_NEAR && bHit==0 ){
+ if( bHit==0
+ && pExpr->eType==FTSQUERY_NEAR
+ && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
+ ){
Fts3Expr *p;
for(p=pExpr; p->pPhrase==0; p=p->pLeft){
- p->pRight->pPhrase->doclist.pList = 0;
+ if( p->pRight->iDocid==pCsr->iPrevId ){
+ fts3EvalZeroPoslist(p->pRight->pPhrase);
+ }
+ }
+ if( p->iDocid==pCsr->iPrevId ){
+ fts3EvalZeroPoslist(p->pPhrase);
}
- p->pPhrase->doclist.pList = 0;
}
break;
break;
default: {
- if( pCsr->pDeferred ){
+ if( pCsr->pDeferred
+ && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
+ ){
Fts3Phrase *pPhrase = pExpr->pPhrase;
- fts3EvalFreeDeferredDoclist(pPhrase);
+ assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
+ if( pExpr->bDeferred ){
+ fts3EvalZeroPoslist(pPhrase);
+ }
*pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
bHit = (pPhrase->doclist.pList!=0);
pExpr->iDocid = pCsr->iPrevId;
Fts3Phrase *pPhrase = pExpr->pPhrase;
if( pPhrase ){
- fts3EvalFreeDeferredDoclist(pPhrase);
+ fts3EvalZeroPoslist(pPhrase);
if( pPhrase->bIncr ){
sqlite3Fts3EvalPhraseCleanup(pPhrase);
memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
}
}
-static int fts3EvalNearStats(
+static int fts3EvalGatherStats(
Fts3Cursor *pCsr,
Fts3Expr *pExpr
){
}
iDocid = pRoot->iDocid;
bEof = pRoot->bEof;
+ assert( pRoot->bStart );
/* Allocate space for the aMSI[] array of each FTSQUERY_PHRASE node */
for(p=pRoot; p; p=p->pLeft){
if( bEof ){
pRoot->bEof = bEof;
}else{
+ /* Caution: pRoot may iterate through docids in ascending or descending
+ ** order. For this reason, even though it seems more defensive, the
+ ** do loop can not be written:
+ **
+ ** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
+ */
fts3EvalRestart(pCsr, pRoot, &rc);
- while( pRoot->iDocid<iDocid && rc==SQLITE_OK ){
+ do {
fts3EvalNext(pCsr, pRoot, &rc);
assert( pRoot->bEof==0 );
- }
+ }while( pRoot->iDocid!=iDocid && rc==SQLITE_OK );
fts3EvalLoadDeferred(pCsr, &rc);
}
}
aiOut[iCol*3 + 2] = pCsr->nDoc;
}
}else{
- rc = fts3EvalNearStats(pCsr, pExpr);
+ rc = fts3EvalGatherStats(pCsr, pExpr);
if( rc==SQLITE_OK ){
assert( pExpr->aMI );
for(iCol=0; iCol<pTab->nColumn; iCol++){
if( pPhrase ){
int i;
sqlite3_free(pPhrase->doclist.aAll);
- fts3EvalFreeDeferredDoclist(pPhrase);
+ fts3EvalZeroPoslist(pPhrase);
memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
for(i=0; i<pPhrase->nToken; i++){
fts3SegReaderCursorFree(pPhrase->aToken[i].pSegcsr);
-C Fix\svarious\sissues\sto\sdo\swith\sdeferred\stokens,\sNEAR\sexpressions\sand\smatchinfo().
-D 2011-06-08T18:39:07.487
+C Fix\sproblems\sto\sdo\swith\susing\sboth\sOR\sand\sNEAR\soperators\sin\sa\ssingle\sexpression.
+D 2011-06-09T10:48:02.352
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 11dcc00a8d0e5202def00e81732784fb0cc4fe1d
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
-F ext/fts3/fts3.c b44083cafb9840be0927f8b9fb2ab4f373167f77
+F ext/fts3/fts3.c 5df3b5797522d3d17949ee12d5918d6d213b5114
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3Int.h a999cfbf605efec293a88519f74192f5204c84d6
F ext/fts3/fts3_aux.c baed9dab7fb4604ae8cafdb2d7700abe93beffbe
F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
F test/fts3prefix.test 36246609111ec1683f7ea5ed27666ce2cefb5676
F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2
-F test/fts3rnd.test d88ec3dbe52e81e410cd1a39554d15941f86333c
+F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0
F test/fts3shared.test 8bb266521d7c5495c0ae522bb4d376ad5387d4a2
F test/fts3snippet.test a12f22a3ba4dd59751a57c79b031d07ab5f51ddd
F test/fts3sort.test 63d52c1812904b751f9e1ff487472e44833f5402
F tool/symbols.sh bc2a3709940d47c8ac8e0a1fdf17ec801f015a00
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings.sh 347d974d143cf132f953b565fbc03026f19fcb4d
-P 9d10a6846b12a9cc8fd4fdc3affd931a27218b5a
-R 37e4da2cb9907d0ccf1d8076445165fd
+P 3972a787df5ec253b99b148385655e7b68d851fa
+R 9f88ec7fe13b9820fcb74aa4a46dd50c
U dan
-Z 147c4bbcabf01e6d99dff7a301984a70
+Z 78f71a9a33e1daee77ff848d72b67bf4