@@ -189,7 +189,7 @@ prsd_headline(PG_FUNCTION_ARGS)
189189 int bestb = -1 ,
190190 beste = -1 ;
191191 int bestlen = -1 ;
192- int pose = 0 ,
192+ int pose = 0 , posb ,
193193 poslen ,
194194 curlen ;
195195
@@ -229,15 +229,15 @@ prsd_headline(PG_FUNCTION_ARGS)
229229 if (min_words >= max_words )
230230 ereport (ERROR ,
231231 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
232- errmsg ("must be MinWords < MaxWords" )));
232+ errmsg ("MinWords must be less than MaxWords" )));
233233 if (min_words <= 0 )
234234 ereport (ERROR ,
235235 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
236- errmsg ("must be MinWords > 0 " )));
236+ errmsg ("MinWords should be positive " )));
237237 if (shortword < 0 )
238238 ereport (ERROR ,
239239 (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
240- errmsg ("must be ShortWord > = 0" )));
240+ errmsg ("ShortWord hould be = 0" )));
241241 }
242242
243243 while (hlCover (prs , query , & p , & q ))
@@ -261,6 +261,7 @@ prsd_headline(PG_FUNCTION_ARGS)
261261 continue ;
262262 }
263263
264+ posb = p ;
264265 if (curlen < max_words )
265266 { /* find good end */
266267 for (i = i - 1 ; i < prs -> curwords && curlen < max_words ; i ++ )
@@ -278,6 +279,19 @@ prsd_headline(PG_FUNCTION_ARGS)
278279 if (curlen >= min_words )
279280 break ;
280281 }
282+ if ( curlen < min_words && i >=prs -> curwords ) { /* got end of text and our cover is shoter than min_words */
283+ for (i = p ; i >= 0 ; i -- ) {
284+ if (!NONWORDTOKEN (prs -> words [i ].type ))
285+ curlen ++ ;
286+ if (prs -> words [i ].item && !prs -> words [i ].repeated )
287+ poslen ++ ;
288+ if (NOENDTOKEN (prs -> words [i ].type ) || prs -> words [i ].len <= shortword )
289+ continue ;
290+ if (curlen >= min_words )
291+ break ;
292+ }
293+ posb = (i >=0 ) ? i : 0 ;
294+ }
281295 }
282296 else
283297 { /* shorter cover :((( */
@@ -298,7 +312,7 @@ prsd_headline(PG_FUNCTION_ARGS)
298312 (bestlen >= 0 && !(NOENDTOKEN (prs -> words [pose ].type ) || prs -> words [pose ].len <= shortword ) &&
299313 (NOENDTOKEN (prs -> words [beste ].type ) || prs -> words [beste ].len <= shortword )))
300314 {
301- bestb = p ;
315+ bestb = posb ;
302316 beste = pose ;
303317 bestlen = poslen ;
304318 }
0 commit comments