aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-04-09 15:38:43 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-04-09 15:38:52 -0400
commit07453e9e332d262d9791e6819fadf74d5a2e8193 (patch)
tree808215d01ba985406cf3a195b4632ee9e37efd27 /src
parentfac00400846b742a0b8c804b3e075b385d5c3668 (diff)
downloadpostgresql-07453e9e332d262d9791e6819fadf74d5a2e8193.tar.gz
postgresql-07453e9e332d262d9791e6819fadf74d5a2e8193.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/tsearch/wparser_def.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c
index 0e963660ecd..8850bf323cd 100644
--- a/src/backend/tsearch/wparser_def.c
+++ b/src/backend/tsearch/wparser_def.c
@@ -2337,22 +2337,24 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, bool highlightall,
/* Mark the chosen fragments (covers) */
mark_fragment(prs, highlightall, startpos, endpos);
num_f++;
- /* exclude overlapping covers */
+ /* Exclude covers overlapping this one from future consideration */
for (i = 0; i < numcovers; i++)
{
if (i != minI &&
- ((covers[i].startpos >= covers[minI].startpos &&
- covers[i].startpos <= covers[minI].endpos) ||
- (covers[i].endpos >= covers[minI].startpos &&
- covers[i].endpos <= covers[minI].endpos)))
+ ((covers[i].startpos >= startpos &&
+ covers[i].startpos <= endpos) ||
+ (covers[i].endpos >= startpos &&
+ covers[i].endpos <= endpos) ||
+ (covers[i].startpos < startpos &&
+ covers[i].endpos > endpos)))
covers[i].excluded = true;
}
}
else
- break;
+ break; /* no selectable covers remain */
}
- /* show at least min_words if we have not marked anything */
+ /* show the first min_words words if we have not marked anything */
if (num_f <= 0)
{
startpos = endpos = curlen = 0;
@@ -2510,6 +2512,7 @@ mark_hl_words(HeadlineParsedText *prs, TSQuery query, bool highlightall,
if (bestlen < 0)
{
curlen = 0;
+ pose = 0;
for (i = 0; i < prs->curwords && curlen < min_words; i++)
{
if (!NONWORDTOKEN(prs->words[i].type))