Fix generation of too long headline with ShortWords.
authorTeodor Sigaev <teodor@sigaev.ru>
Thu, 15 Jan 2009 18:29:47 +0000 (18:29 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Thu, 15 Jan 2009 18:29:47 +0000 (18:29 +0000)
Per http://archives.postgresql.org/pgsql-hackers/2008-09/msg01088.php

contrib/tsearch2/wparser_def.c

index 352fae298c43551b485710b59d1dafb78366871f..53199992c8e205c958f8b27edde1573784f682cd 100644 (file)
@@ -280,11 +280,13 @@ prsd_headline(PG_FUNCTION_ARGS)
                    break;
            }
            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)