Index: ext/fts1/fts1.c ================================================================== --- ext/fts1/fts1.c +++ ext/fts1/fts1.c @@ -177,10 +177,22 @@ DL_DOCIDS, /* docids only */ DL_POSITIONS, /* docids + positions */ DL_POSITIONS_OFFSETS /* docids + positions + offsets */ } DocListType; +/* +** By default, positions and offsets are stored in the doclists. +** To change this so that only positions are stored, compile +** with +** +** -DDL_DEFAULT=DL_POSITIONS +** +*/ +#ifndef DL_DEFAULT +# define DL_DEFAULT DL_POSITIONS_OFFSETS +#endif + typedef struct DocList { char *pData; int nData; DocListType iType; int iLastColumn; /* the last column written */ @@ -271,22 +283,32 @@ assert( d->iType==DL_POSITIONS ); addPos(d, iColumn, iPos); appendVarint(d, POS_END); /* add new terminator */ } -static void docListAddPosOffset(DocList *d, int iColumn, int iPos, - int iStartOffset, int iEndOffset){ - assert( d->iType==DL_POSITIONS_OFFSETS ); +/* +** Add a position and starting and ending offsets to a doclist. +** +** If the doclist is setup to handle only positions, then insert +** the position only and ignore the offsets. +*/ +static void docListAddPosOffset( + DocList *d, /* Doclist under construction */ + int iColumn, /* Column the inserted term is part of */ + int iPos, /* Position of the inserted term */ + int iStartOffset, /* Starting offset of inserted term */ + int iEndOffset /* Ending offset of inserted term */ +){ + assert( d->iType>=DL_POSITIONS ); addPos(d, iColumn, iPos); - - assert( iStartOffset>=d->iLastOffset ); - appendVarint(d, iStartOffset-d->iLastOffset); - d->iLastOffset = iStartOffset; - - assert( iEndOffset>=iStartOffset ); - appendVarint(d, iEndOffset-iStartOffset); - + if( d->iType==DL_POSITIONS_OFFSETS ){ + assert( iStartOffset>=d->iLastOffset ); + appendVarint(d, iStartOffset-d->iLastOffset); + d->iLastOffset = iStartOffset; + assert( iEndOffset>=iStartOffset ); + appendVarint(d, iEndOffset-iStartOffset); + } appendVarint(d, POS_END); /* add new terminator */ } /* ** A DocListReader object is a cursor into a doclist. Initialize @@ -1297,11 +1319,11 @@ rc = sql_step_statement(v, TERM_SELECT_STMT, &s); if( rc!=SQLITE_ROW ) return rc; *rowid = sqlite3_column_int64(s, 0); - docListInit(out, DL_POSITIONS_OFFSETS, + docListInit(out, DL_DEFAULT, sqlite3_column_blob(s, 1), sqlite3_column_bytes(s, 1)); /* We expect only one row. We must execute another sqlite3_step() * to complete the iteration; otherwise the table will remain locked. */ rc = sqlite3_step(s); @@ -1332,11 +1354,11 @@ if( rc!=SQLITE_OK ) return rc; rc = sqlite3_bind_text(s, 1, pTerm, nTerm, SQLITE_STATIC); if( rc!=SQLITE_OK ) return rc; - docListInit(&doclist, DL_POSITIONS_OFFSETS, 0, 0); + docListInit(&doclist, DL_DEFAULT, 0, 0); /* TODO(shess) Handle schema and busy errors. */ while( (rc=sql_step_statement(v, TERM_SELECT_ALL_STMT, &s))==SQLITE_ROW ){ DocList old; @@ -2915,11 +2937,11 @@ return SQLITE_ERROR; } p = fts1HashFind(terms, pToken, nTokenBytes); if( p==NULL ){ - p = docListNew(DL_POSITIONS_OFFSETS); + p = docListNew(DL_DEFAULT); docListAddDocid(p, iDocid); fts1HashInsert(terms, pToken, nTokenBytes, p); } if( iColumn>=0 ){ docListAddPosOffset(p, iColumn, iPosition, iStartOffset, iEndOffset); @@ -2942,11 +2964,11 @@ DocList doclist; int iSegment = 0, rc; rc = term_select(v, pTerm, nTerm, iSegment, &iIndexRow, &doclist); if( rc==SQLITE_DONE ){ - docListInit(&doclist, DL_POSITIONS_OFFSETS, 0, 0); + docListInit(&doclist, DL_DEFAULT, 0, 0); docListUpdate(&doclist, d); /* TODO(shess) Consider length(doclist)>CHUNK_MAX? */ rc = term_insert(v, NULL, pTerm, nTerm, iSegment, &doclist); goto err; }