Skip to content

Commit 2e0e409

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 a4d4f59 commit 2e0e409

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
@@ -2337,22 +2337,24 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, bool highlightall,
23372337
/* Mark the chosen fragments (covers) */
23382338
mark_fragment(prs, highlightall, startpos, endpos);
23392339
num_f++;
2340-
/* exclude overlapping covers */
2340+
/* Exclude covers overlapping this one from future consideration */
23412341
for (i = 0; i < numcovers; i++)
23422342
{
23432343
if (i != minI &&
2344-
((covers[i].startpos >= covers[minI].startpos &&
2345-
covers[i].startpos <= covers[minI].endpos) ||
2346-
(covers[i].endpos >= covers[minI].startpos &&
2347-
covers[i].endpos <= covers[minI].endpos)))
2344+
((covers[i].startpos >= startpos &&
2345+
covers[i].startpos <= endpos) ||
2346+
(covers[i].endpos >= startpos &&
2347+
covers[i].endpos <= endpos) ||
2348+
(covers[i].startpos < startpos &&
2349+
covers[i].endpos > endpos)))
23482350
covers[i].excluded = true;
23492351
}
23502352
}
23512353
else
2352-
break;
2354+
break; /* no selectable covers remain */
23532355
}
23542356

2355-
/* show at least min_words if we have not marked anything */
2357+
/* show the first min_words words if we have not marked anything */
23562358
if (num_f <= 0)
23572359
{
23582360
startpos = endpos = curlen = 0;
@@ -2510,6 +2512,7 @@ mark_hl_words(HeadlineParsedText *prs, TSQuery query, bool highlightall,
25102512
if (bestlen < 0)
25112513
{
25122514
curlen = 0;
2515+
pose = 0;
25132516
for (i = 0; i < prs->curwords && curlen < min_words; i++)
25142517
{
25152518
if (!NONWORDTOKEN(prs->words[i].type))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy