Skip to content

Commit 9be664d

Browse files
committed
Further cleanup of ts_headline code.
Suppress a probably-meaningless uninitialized-variable warning (induced by my previous patch, I'm sorry to say). Improve mark_hl_fragments()'s test for overlapping cover strings: it failed to consider the possibility that the current string is strictly within another one. That's unlikely given the preceding splitting into MaxWords fragments, but I don't think it's impossible. Discussion: https://postgr.es/m/16345-2e0cf5cddbdcd3b4@postgresql.org
1 parent 2971180 commit 9be664d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/backend/tsearch/wparser_def.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,22 +2434,24 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, bool highlightall,
24342434
/* Mark the chosen fragments (covers) */
24352435
mark_fragment(prs, highlightall, startpos, endpos);
24362436
num_f++;
2437-
/* exclude overlapping covers */
2437+
/* Exclude covers overlapping this one from future consideration */
24382438
for (i = 0; i < numcovers; i++)
24392439
{
24402440
if (i != minI &&
2441-
((covers[i].startpos >= covers[minI].startpos &&
2442-
covers[i].startpos <= covers[minI].endpos) ||
2443-
(covers[i].endpos >= covers[minI].startpos &&
2444-
covers[i].endpos <= covers[minI].endpos)))
2441+
((covers[i].startpos >= startpos &&
2442+
covers[i].startpos <= endpos) ||
2443+
(covers[i].endpos >= startpos &&
2444+
covers[i].endpos <= endpos) ||
2445+
(covers[i].startpos < startpos &&
2446+
covers[i].endpos > endpos)))
24452447
covers[i].excluded = true;
24462448
}
24472449
}
24482450
else
2449-
break;
2451+
break; /* no selectable covers remain */
24502452
}
24512453

2452-
/* show at least min_words if we have not marked anything */
2454+
/* show the first min_words words if we have not marked anything */
24532455
if (num_f <= 0)
24542456
{
24552457
startpos = endpos = curlen = 0;
@@ -2607,6 +2609,7 @@ mark_hl_words(HeadlineParsedText *prs, TSQuery query, bool highlightall,
26072609
if (bestlen < 0)
26082610
{
26092611
curlen = 0;
2612+
pose = 0;
26102613
for (i = 0; i < prs->curwords && curlen < min_words; i++)
26112614
{
26122615
if (!NONWORDTOKEN(prs->words[i].type))

0 commit comments

Comments
 (0)