From 32cfb33244774be5d64174d15d705f5dffaccecf Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 15 Jan 2009 17:44:18 +0000 Subject: [PATCH] Fix generation of too long headline with ShortWords. Per http://archives.postgresql.org/pgsql-hackers/2008-09/msg01088.php --- contrib/tsearch2/wparser_def.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/tsearch2/wparser_def.c b/contrib/tsearch2/wparser_def.c index f1f168de90..8bb4d3c768 100644 --- a/contrib/tsearch2/wparser_def.c +++ b/contrib/tsearch2/wparser_def.c @@ -301,12 +301,14 @@ prsd_headline(PG_FUNCTION_ARGS) if (curlen < min_words && i >= prs->curwords) { /* got end of text and our cover is shoter * than min_words */ - for (i = p; i >= 0; i--) + for (i = p - 1 ; i >= 0; i--) { if (!NONWORDTOKEN(prs->words[i].type)) curlen++; if (prs->words[i].item && !prs->words[i].repeated) poslen++; + if ( curlen >= max_words ) + break; if (NOENDTOKEN(prs->words[i].type) || prs->words[i].len <= shortword) continue; if (curlen >= min_words)