postgres.git / summary / log / commit / refs

commit    9be664d715ebcb7265c6f3e2bdba89de2b45d66c
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Thu Apr 09 19:38:43 2020 +0000
First released in: 13.0, 9.6.18, 10.13, 11.8, 12.3

    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


src/backend/tsearch/wparser_def.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c index d9bf1e3e1bc..8fecfd4f6f8 100644 --- a/src/backend/tsearch/wparser_def.c +++ b/src/backend/tsearch/wparser_def.c @@ -2434,22 +2434,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; @@ -2607,6 +2609,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)) [parent: 2971180929b6]