patch for space around the FragmentDelimiter

Started by Sushant Sinhaabout 17 years ago3 messageshackers
Jump to latest
#1Sushant Sinha
sushant354@gmail.com

FragmentDelimiter is an argument for ts_headline function to separates
different headline fragments. The default delimiter is " ... ".
Currently if someone specifies the delimiter as an option to the
function, no extra space is added around the delimiter. However, it does
not look good without space around the delimter.

Since the option parsing function removes any space around the given
value, it is not possible to add any desired space. The attached patch
adds space when a FragmentDelimiter is specified.

QUERY:

SELECT ts_headline('english', '
Day after day, day after day,
We stuck, nor breath nor motion,
As idle as a painted Ship
Upon a painted Ocean.
Water, water, every where
And all the boards did shrink;
Water, water, every where,
Nor any drop to drink.
S. T. Coleridge (1772-1834)
', to_tsquery('english', 'Coleridge & stuck'),
'MaxFragments=2,FragmentDelimiter=***');

OLD RESULT
ts_headline
--------------------------------------------
after day, day after day,
We <b>stuck</b>, nor breath nor motion,
As idle as a painted Ship
Upon a painted Ocean.
Water, water, every where
And all the boards did shrink;
Water, water, every where***drop to drink.
S. T. <b>Coleridge</b>
(1 row)

NEW RESULT after the patch

ts_headline
----------------------------------------------
after day, day after day,
We <b>stuck</b>, nor breath nor motion,
As idle as a painted Ship
Upon a painted Ocean.
Water, water, every where
And all the boards did shrink;
Water, water, every where *** drop to drink.
S. T. <b>Coleridge</b>

Attachments:

fragment_delimiter.patchtext/x-patch; charset=UTF-8; name=fragment_delimiter.patchDownload+15-14
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Sushant Sinha (#1)
Re: patch for space around the FragmentDelimiter

Sushant Sinha <sushant354@gmail.com> writes:

FragmentDelimiter is an argument for ts_headline function to separates
different headline fragments. The default delimiter is " ... ".
Currently if someone specifies the delimiter as an option to the
function, no extra space is added around the delimiter. However, it does
not look good without space around the delimter.

Maybe not to you, for the particular delimiter you happen to be working
with, but it doesn't follow that spaces are always appropriate.

Since the option parsing function removes any space around the given
value, it is not possible to add any desired space. The attached patch
adds space when a FragmentDelimiter is specified.

I think this is a pretty bad idea. Better would be to document how to
get spaces into the delimiter, ie, use double quotes:

... FragmentDelimiter = " ... " ...

Hmm, actually, it looks to me that the documentation already shows this,
in the example of the default values.

regards, tom lane

#3Sushant Sinha
sushant354@gmail.com
In reply to: Tom Lane (#2)
Re: patch for space around the FragmentDelimiter

yeah you are right. I did not know that you can pass space using double
quotes.

-Sushant.

Show quoted text

On Sun, 2009-03-01 at 20:49 -0500, Tom Lane wrote:

Sushant Sinha <sushant354@gmail.com> writes:

FragmentDelimiter is an argument for ts_headline function to separates
different headline fragments. The default delimiter is " ... ".
Currently if someone specifies the delimiter as an option to the
function, no extra space is added around the delimiter. However, it does
not look good without space around the delimter.

Maybe not to you, for the particular delimiter you happen to be working
with, but it doesn't follow that spaces are always appropriate.

Since the option parsing function removes any space around the given
value, it is not possible to add any desired space. The attached patch
adds space when a FragmentDelimiter is specified.

I think this is a pretty bad idea. Better would be to document how to
get spaces into the delimiter, ie, use double quotes:

... FragmentDelimiter = " ... " ...

Hmm, actually, it looks to me that the documentation already shows this,
in the example of the default values.

regards, tom lane