SQLite

Check-in [b174ed2bde]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a bug in the fts5 snippet function causing it to return text containing zero phrase instances.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fts5-snippet-bias
Files: files | file ages | folders
SHA1: b174ed2bde43a1872374ce18b85ac9f067e86fbb
User & Date: dan 2016-08-24 18:50:47.193
Context
2016-08-27
18:34
Fixes to fts5 snippet() function. (check-in: d464a7b18d user: dan tags: trunk)
2016-08-24
18:50
Fix a bug in the fts5 snippet function causing it to return text containing zero phrase instances. (Closed-Leaf check-in: b174ed2bde user: dan tags: fts5-snippet-bias)
2016-08-20
17:23
Fix other minor problems with the fts5 snippet() function. (check-in: b56b2a85cf user: dan tags: fts5-snippet-bias)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts5/fts5_aux.c.
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  int i;
  int ip = 0;
  int ic = 0;
  int iOff = 0;
  int iFirst = -1;
  int nInst;
  int nScore = 0;


  rc = pApi->xInstCount(pFts, &nInst);
  for(i=0; i<nInst && rc==SQLITE_OK; i++){
    rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
    if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
      nScore += (aSeen[ip] ? 1 : 1000);
      aSeen[ip] = 1;
      if( iFirst<0 ) iFirst = iOff;

    }
  }

  *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;
  }

  return rc;
}







>








>





<

<







327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349

350
351
352
353
354
355
356
  int i;
  int ip = 0;
  int ic = 0;
  int iOff = 0;
  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++){
    rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
    if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
      nScore += (aSeen[ip] ? 1 : 1000);
      aSeen[ip] = 1;
      if( iFirst<0 ) iFirst = iOff;
      iLast = iOff + pApi->xPhraseSize(pFts, ip);
    }
  }

  *pnScore = nScore;
  if( piPos ){

    int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;

    if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
    if( iAdj<0 ) iAdj = 0;
    *piPos = iAdj;
  }

  return rc;
}
Changes to ext/fts5/test/fts5af.test.
160
161
162
163
164
165
166











167
168
169
170
  CREATE VIRTUAL TABLE x1 USING fts5(a, b);
  INSERT INTO x1 VALUES('xyz', '1 2 3 4 5 6 7 8 9 10 11 12 13');
  SELECT snippet(x1, 1, '[', ']', '...', 5) FROM x1('xyz');
} {
  {1 2 3 4 5...}
}












} ;# foreach_detail_mode 

finish_test








>
>
>
>
>
>
>
>
>
>
>




160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  CREATE VIRTUAL TABLE x1 USING fts5(a, b);
  INSERT INTO x1 VALUES('xyz', '1 2 3 4 5 6 7 8 9 10 11 12 13');
  SELECT snippet(x1, 1, '[', ']', '...', 5) FROM x1('xyz');
} {
  {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