pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
12+ messages / 4 participants
[nested] [flat]

* BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
@ 2013-08-02 07:03 alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: alex@hill.net.au @ 2013-08-02 07:03 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8354
Logged by:          Alex Hill
Email address:      alex@hill.net.au
PostgreSQL version: 9.2.4
Operating system:   OS X 10.8.4 Mountain Lion
Description:        

Hi all,


The docs for ts_rank_cd state:


"This function requires positional information in its input. Therefore it
will not work on "stripped" tsvector values — it will always return zero."


However if a tsvector contains some stripped lexemes and some non-stripped,
ts_rank_cd will rank extents including the non-stripped values.


For example, this evaluates to zero as expected:


    SELECT ts_rank_cd(strip(to_tsvector('text search')),
plainto_tsquery('text search'))




But this doesn't:


    SELECT ts_rank_cd(to_tsvector('text') || strip(to_tsvector('search')),
plainto_tsquery('text search'))




I think this is a bug, if not in the code then in the documentation, which
isn't clear on what happens when stripped and positioned lexemes are mixed
in one tsvector.


I would prefer that stripped lexemes were completely ignored by ts_rank_cd:
my use case is using this as a fifth pseudo-weight, which matches a @@ query
but doesn't add to a ts_rank_cd ranking.


What do you think?


Cheers,
Alex



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
@ 2014-01-31 21:22 ` Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-01-31 21:22 UTC (permalink / raw)
  To: alex@hill.net.au; +Cc: pgsql-bugs


Would someone please comment on this text search bug report?  Thanks.

---------------------------------------------------------------------------

On Fri, Aug  2, 2013 at 07:03:42AM +0000, alex@hill.net.au wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      8354
> Logged by:          Alex Hill
> Email address:      alex@hill.net.au
> PostgreSQL version: 9.2.4
> Operating system:   OS X 10.8.4 Mountain Lion
> Description:        
> 
> Hi all,
> 
> 
> The docs for ts_rank_cd state:
> 
> 
> "This function requires positional information in its input. Therefore it
> will not work on "stripped" tsvector values — it will always return zero."
> 
> 
> However if a tsvector contains some stripped lexemes and some non-stripped,
> ts_rank_cd will rank extents including the non-stripped values.
> 
> 
> For example, this evaluates to zero as expected:
> 
> 
>     SELECT ts_rank_cd(strip(to_tsvector('text search')),
> plainto_tsquery('text search'))
> 
> 
> 
> 
> But this doesn't:
> 
> 
>     SELECT ts_rank_cd(to_tsvector('text') || strip(to_tsvector('search')),
> plainto_tsquery('text search'))
> 
> 
> 
> 
> I think this is a bug, if not in the code then in the documentation, which
> isn't clear on what happens when stripped and positioned lexemes are mixed
> in one tsvector.
> 
> 
> I would prefer that stripped lexemes were completely ignored by ts_rank_cd:
> my use case is using this as a fifth pseudo-weight, which matches a @@ query
> but doesn't add to a ts_rank_cd ranking.
> 
> 
> What do you think?
> 
> 
> Cheers,
> Alex
> 
> 
> 
> -- 
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-02-06 18:07   ` Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Hill @ 2014-02-06 18:07 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-bugs

Hi Bruce, all,

I think this can be solved (if it's agreed that it's a bug) in a pretty
straightforward way: when creating the document representation used in
calculating cover density rank, we can just skip lexemes with no position
entirely.

Fix and tests here: https://github.com/AlexHill/postgres/compare/bug_8354

As a patch file here:
https://github.com/AlexHill/postgres/commit/cd522b254d166d569b86803115f0f499864e949b.patch

Cheers,
Alex





On Sat, Feb 1, 2014 at 5:22 AM, Bruce Momjian <bruce@momjian.us> wrote:

>
> Would someone please comment on this text search bug report?  Thanks.
>
> ---------------------------------------------------------------------------
>
> On Fri, Aug  2, 2013 at 07:03:42AM +0000, alex@hill.net.au wrote:
> > The following bug has been logged on the website:
> >
> > Bug reference:      8354
> > Logged by:          Alex Hill
> > Email address:      alex@hill.net.au
> > PostgreSQL version: 9.2.4
> > Operating system:   OS X 10.8.4 Mountain Lion
> > Description:
> >
> > Hi all,
> >
> >
> > The docs for ts_rank_cd state:
> >
> >
> > "This function requires positional information in its input. Therefore it
> > will not work on "stripped" tsvector values -- it will always return
> zero."
> >
> >
> > However if a tsvector contains some stripped lexemes and some
> non-stripped,
> > ts_rank_cd will rank extents including the non-stripped values.
> >
> >
> > For example, this evaluates to zero as expected:
> >
> >
> >     SELECT ts_rank_cd(strip(to_tsvector('text search')),
> > plainto_tsquery('text search'))
> >
> >
> >
> >
> > But this doesn't:
> >
> >
> >     SELECT ts_rank_cd(to_tsvector('text') ||
> strip(to_tsvector('search')),
> > plainto_tsquery('text search'))
> >
> >
> >
> >
> > I think this is a bug, if not in the code then in the documentation,
> which
> > isn't clear on what happens when stripped and positioned lexemes are
> mixed
> > in one tsvector.
> >
> >
> > I would prefer that stripped lexemes were completely ignored by
> ts_rank_cd:
> > my use case is using this as a fifth pseudo-weight, which matches a @@
> query
> > but doesn't add to a ts_rank_cd ranking.
> >
> >
> > What do you think?
> >
> >
> > Cheers,
> > Alex
> >
> >
> >
> > --
> > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-bugs
>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
>   + Everyone has their own god. +
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
@ 2014-02-11 15:45     ` Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-02-11 15:45 UTC (permalink / raw)
  To: Alexander Hill <alex@hill.net.au>; +Cc: pgsql-bugs

On Fri, Feb  7, 2014 at 02:07:59AM +0800, Alexander Hill wrote:
> Hi Bruce, all,
> 
> I think this can be solved (if it's agreed that it's a bug) in a pretty
> straightforward way: when creating the document representation used in
> calculating cover density rank, we can just skip lexemes with no position
> entirely.
> 
> Fix and tests here: https://github.com/AlexHill/postgres/compare/bug_8354
> 
> As a patch file here: https://github.com/AlexHill/postgres/commit/
> cd522b254d166d569b86803115f0f499864e949b.patch 

OK, great.  I am attaching this patch.  Would this change the contents
of any indexes?  That would be a problem for pg_upgrade.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

tsrank.patch (text/x-diff, 1.7K) download diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c index c9e71c9..bb220d4 100644 --- a/src/backend/utils/adt/tsrank.c +++ b/src/backend/utils/adt/tsrank.c @@ -658,8 +658,8 @@ } else { - dimt = POSNULL.npos; - post = POSNULL.pos; + entry++; + continue; } while (cur + dimt >= len) diff --git a/src/test/regress/expected/tsearch.out b/src/test/regress/expected/tsearch.out index 9341dbe..3bbfb655 100644 --- a/src/test/regress/expected/tsearch.out +++ b/src/test/regress/expected/tsearch.out @@ -596,6 +596,20 @@ S. T. Coleridge (1772-1834) 0.1 (1 row) +SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both&stripped')); + ts_rank_cd +------------ + 0 +(1 row) + +SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped&stripped')); + ts_rank_cd +------------ + 0 +(1 row) + --headline tests SELECT ts_headline('english', ' Day after day, day after day, diff --git a/src/test/regress/sql/tsearch.sql b/src/test/regress/sql/tsearch.sql index 9fd1207..1f21826 100644 --- a/src/test/regress/sql/tsearch.sql +++ b/src/test/regress/sql/tsearch.sql @@ -165,6 +165,12 @@ Water, water, every where, S. T. Coleridge (1772-1834) '), to_tsquery('english', 'ocean')); +SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both&stripped')); + +SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped&stripped')); + --headline tests SELECT ts_headline('english', ' Day after day, day after day, -- 1.8.5.1
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-02-12 01:49       ` Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Hill @ 2014-02-12 01:49 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-bugs

Hi Bruce,

In normal use this won't affect any data that ends up in an index.

The only exception would be where somebody has created an index over the
result of ts_rank_cd - indexing search rank for the most common search
terms, maybe?

But that's true of any function whose result is indexed. What's the upgrade
policy in that case?

Cheers,
Alex


On Tue, Feb 11, 2014 at 11:45 PM, Bruce Momjian <bruce@momjian.us> wrote:

> On Fri, Feb  7, 2014 at 02:07:59AM +0800, Alexander Hill wrote:
> > Hi Bruce, all,
> >
> > I think this can be solved (if it's agreed that it's a bug) in a pretty
> > straightforward way: when creating the document representation used in
> > calculating cover density rank, we can just skip lexemes with no position
> > entirely.
> >
> > Fix and tests here:
> https://github.com/AlexHill/postgres/compare/bug_8354
> >
> > As a patch file here: https://github.com/AlexHill/postgres/commit/
> > cd522b254d166d569b86803115f0f499864e949b.patch
>
> OK, great.  I am attaching this patch.  Would this change the contents
> of any indexes?  That would be a problem for pg_upgrade.
>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
>   + Everyone has their own god. +
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
@ 2014-02-12 14:31         ` Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-02-12 14:31 UTC (permalink / raw)
  To: Alexander Hill <alex@hill.net.au>; +Cc: pgsql-bugs

On Wed, Feb 12, 2014 at 09:49:32AM +0800, Alexander Hill wrote:
> Hi Bruce,
> 
> In normal use this won't affect any data that ends up in an index.
> 
> The only exception would be where somebody has created an index over the result
> of ts_rank_cd - indexing search rank for the most common search terms, maybe?

OK, good.

> But that's true of any function whose result is indexed. What's the upgrade
> policy in that case?

Well, we document that the function output changed, and if anyone is
using the function for an index, they need to rebuild the index, so I
think we are fine fixing this for 9.4.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-03-21 06:29           ` Alexander Hill <alex@hill.net.au>
  2014-03-21 13:43             ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Hill @ 2014-03-21 06:29 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-bugs

Hi Bruce,

I've just updated the docs for ts_rank_cd in my fork to reflect this
change. Would be great if that could make it in too.

Patch here:
https://github.com/AlexHill/postgres/commit/3e5d86ea23d82b07188192411cdc5c5a5194a5ae.patch

Is there anything else I need to do to make sure this patch ends up in 9.4?

Cheers,

Alex
On Feb 12, 2014 10:31 PM, "Bruce Momjian" <bruce@momjian.us> wrote:

> On Wed, Feb 12, 2014 at 09:49:32AM +0800, Alexander Hill wrote:
> > Hi Bruce,
> >
> > In normal use this won't affect any data that ends up in an index.
> >
> > The only exception would be where somebody has created an index over the
> result
> > of ts_rank_cd - indexing search rank for the most common search terms,
> maybe?
>
> OK, good.
>
> > But that's true of any function whose result is indexed. What's the
> upgrade
> > policy in that case?
>
> Well, we document that the function output changed, and if anyone is
> using the function for an index, they need to rebuild the index, so I
> think we are fine fixing this for 9.4.
>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
>   + Everyone has their own god. +
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
@ 2014-03-21 13:43             ` Bruce Momjian <bruce@momjian.us>
  2014-03-21 14:45               ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-03-21 13:43 UTC (permalink / raw)
  To: Alexander Hill <alex@hill.net.au>; +Cc: pgsql-bugs

On Fri, Mar 21, 2014 at 02:29:26PM +0800, Alexander Hill wrote:
> Hi Bruce,
> 
> I've just updated the docs for ts_rank_cd in my fork to reflect this change.
> Would be great if that could make it in too.
> 
> Patch here: https://github.com/AlexHill/postgres/commit/
> 3e5d86ea23d82b07188192411cdc5c5a5194a5ae.patch
> 
> Is there anything else I need to do to make sure this patch ends up in 9.4?

OK, combined patch attached.  Is this correct?  I keep hoping someone
else will chime in with an opinion on this, but at this point I think
what you have done is clear enough for me to commit for 9.4.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

rank.diff (text/x-diff, 3.0K) download diff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgml new file mode 100644 index 604e545..a4418ef *** a/doc/src/sgml/textsearch.sgml --- b/doc/src/sgml/textsearch.sgml *************** SELECT plainto_tsquery('english', 'The F *** 891,897 **** <para> This function requires positional information in its input. Therefore it will not work on <quote>stripped</> <type>tsvector</> ! values &mdash; it will always return zero. </para> </listitem> </varlistentry> --- 891,901 ---- <para> This function requires positional information in its input. Therefore it will not work on <quote>stripped</> <type>tsvector</> ! values &mdash; it will always return zero. If a <type>tsvector</> ! contains stripped and unstripped lexemes, only the unstripped lexemes ! will be considered. (See <xref linkend="textsearch-manipulate-tsvector"> ! for more information about the <function>strip</> function and ! positional information in <type>tsvector</>s.) </para> </listitem> </varlistentry> diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c new file mode 100644 index c9e71c9..bb220d4 *** a/src/backend/utils/adt/tsrank.c --- b/src/backend/utils/adt/tsrank.c *************** get_docrep(TSVector txt, QueryRepresenta *** 658,665 **** } else { ! dimt = POSNULL.npos; ! post = POSNULL.pos; } while (cur + dimt >= len) --- 658,665 ---- } else { ! entry++; ! continue; } while (cur + dimt >= len) diff --git a/src/test/regress/expected/tsearch.out b/src/test/regress/expected/tsearch.out new file mode 100644 index 9341dbe..d22d345 *** a/src/test/regress/expected/tsearch.out --- b/src/test/regress/expected/tsearch.out *************** S. T. Coleridge (1772-1834) *** 596,601 **** --- 596,615 ---- 0.1 (1 row) + SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both & stripped')); + ts_rank_cd + ------------ + 0 + (1 row) + + SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped & stripped')); + ts_rank_cd + ------------ + 0 + (1 row) + --headline tests SELECT ts_headline('english', ' Day after day, day after day, diff --git a/src/test/regress/sql/tsearch.sql b/src/test/regress/sql/tsearch.sql new file mode 100644 index 9fd1207..fa460cd *** a/src/test/regress/sql/tsearch.sql --- b/src/test/regress/sql/tsearch.sql *************** Water, water, every where, *** 165,170 **** --- 165,176 ---- S. T. Coleridge (1772-1834) '), to_tsquery('english', 'ocean')); + SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both & stripped')); + + SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped & stripped')); + --headline tests SELECT ts_headline('english', ' Day after day, day after day,
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-03-21 13:43             ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-03-21 14:45               ` Tom Lane <tgl@sss.pgh.pa.us>
  2014-03-21 22:10                 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Tom Lane @ 2014-03-21 14:45 UTC (permalink / raw)
  To: Bruce Momjian <bruce@momjian.us>; +Cc: Alexander Hill <alex@hill.net.au>; pgsql-bugs

Bruce Momjian <bruce@momjian.us> writes:
> OK, combined patch attached.  Is this correct?  I keep hoping someone
> else will chime in with an opinion on this, but at this point I think
> what you have done is clear enough for me to commit for 9.4.

That whole function is seriously undercommented; I suppose it's not this
patch's charter to fix that, but we could at least write

!		       	        /* ignore words without positions */
! 				entry++;
! 				continue;

The proposed new documentation text seems pretty badly written.  How about

This function requires lexeme positional information to perform its
calculation.  Therefore it ignores any <quote>stripped</> lexemes in the
<type>tsvector</>.  If there are no unstripped lexemes in the input, the
result will be zero.

The parenthetical "See" text is ok.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-03-21 13:43             ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 14:45               ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Tom Lane <tgl@sss.pgh.pa.us>
@ 2014-03-21 22:10                 ` Bruce Momjian <bruce@momjian.us>
  2014-03-24 18:37                   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-03-21 22:10 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alexander Hill <alex@hill.net.au>; pgsql-bugs

On Fri, Mar 21, 2014 at 10:45:18AM -0400, Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > OK, combined patch attached.  Is this correct?  I keep hoping someone
> > else will chime in with an opinion on this, but at this point I think
> > what you have done is clear enough for me to commit for 9.4.
> 
> That whole function is seriously undercommented; I suppose it's not this
> patch's charter to fix that, but we could at least write
> 
> !		       	        /* ignore words without positions */
> ! 				entry++;
> ! 				continue;
> 
> The proposed new documentation text seems pretty badly written.  How about
> 
> This function requires lexeme positional information to perform its
> calculation.  Therefore it ignores any <quote>stripped</> lexemes in the
> <type>tsvector</>.  If there are no unstripped lexemes in the input, the
> result will be zero.
> 
> The parenthetical "See" text is ok.

OK, thanks.  Updated patch attached.  If Alexander Hill would like to
add more C comments to any of the ts*.c files, or docs explaining what
"cover desity" is, I would be glad to include those in the patch as
well.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

rank.diff (text/x-diff, 3.1K) download diff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgml new file mode 100644 index 604e545..9e78286 *** a/doc/src/sgml/textsearch.sgml --- b/doc/src/sgml/textsearch.sgml *************** SELECT plainto_tsquery('english', 'The F *** 889,897 **** </para> <para> ! This function requires positional information in its input. ! Therefore it will not work on <quote>stripped</> <type>tsvector</> ! values &mdash; it will always return zero. </para> </listitem> </varlistentry> --- 889,901 ---- </para> <para> ! This function requires lexeme positional information to perform ! its calculation. Therefore, it ignores any <quote>stripped</> ! lexemes in the <type>tsvector</>. If there are no unstripped ! lexemes in the input, the result will be zero. (See <xref ! linkend="textsearch-manipulate-tsvector"> for more information ! about the <function>strip</> function and positional information ! in <type>tsvector</>s.) </para> </listitem> </varlistentry> diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c new file mode 100644 index c9e71c9..dcb681d *** a/src/backend/utils/adt/tsrank.c --- b/src/backend/utils/adt/tsrank.c *************** get_docrep(TSVector txt, QueryRepresenta *** 658,665 **** } else { ! dimt = POSNULL.npos; ! post = POSNULL.pos; } while (cur + dimt >= len) --- 658,666 ---- } else { ! /* ignore words without positions */ ! entry++; ! continue; } while (cur + dimt >= len) diff --git a/src/test/regress/expected/tsearch.out b/src/test/regress/expected/tsearch.out new file mode 100644 index 9341dbe..d22d345 *** a/src/test/regress/expected/tsearch.out --- b/src/test/regress/expected/tsearch.out *************** S. T. Coleridge (1772-1834) *** 596,601 **** --- 596,615 ---- 0.1 (1 row) + SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both & stripped')); + ts_rank_cd + ------------ + 0 + (1 row) + + SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped & stripped')); + ts_rank_cd + ------------ + 0 + (1 row) + --headline tests SELECT ts_headline('english', ' Day after day, day after day, diff --git a/src/test/regress/sql/tsearch.sql b/src/test/regress/sql/tsearch.sql new file mode 100644 index 9fd1207..fa460cd *** a/src/test/regress/sql/tsearch.sql --- b/src/test/regress/sql/tsearch.sql *************** Water, water, every where, *** 165,170 **** --- 165,176 ---- S. T. Coleridge (1772-1834) '), to_tsquery('english', 'ocean')); + SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both & stripped')); + + SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped & stripped')); + --headline tests SELECT ts_headline('english', ' Day after day, day after day,
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-03-21 13:43             ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 14:45               ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Tom Lane <tgl@sss.pgh.pa.us>
  2014-03-21 22:10                 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-03-24 18:37                   ` Bruce Momjian <bruce@momjian.us>
  2014-03-24 19:49                     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2014-03-24 18:37 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alexander Hill <alex@hill.net.au>; pgsql-bugs

On Fri, Mar 21, 2014 at 06:10:15PM -0400, Bruce Momjian wrote:
> On Fri, Mar 21, 2014 at 10:45:18AM -0400, Tom Lane wrote:
> > Bruce Momjian <bruce@momjian.us> writes:
> > > OK, combined patch attached.  Is this correct?  I keep hoping someone
> > > else will chime in with an opinion on this, but at this point I think
> > > what you have done is clear enough for me to commit for 9.4.
> > 
> > That whole function is seriously undercommented; I suppose it's not this
> > patch's charter to fix that, but we could at least write
> > 
> > !		       	        /* ignore words without positions */
> > ! 				entry++;
> > ! 				continue;
> > 
> > The proposed new documentation text seems pretty badly written.  How about
> > 
> > This function requires lexeme positional information to perform its
> > calculation.  Therefore it ignores any <quote>stripped</> lexemes in the
> > <type>tsvector</>.  If there are no unstripped lexemes in the input, the
> > result will be zero.
> > 
> > The parenthetical "See" text is ok.
> 
> OK, thanks.  Updated patch attached.  If Alexander Hill would like to
> add more C comments to any of the ts*.c files, or docs explaining what
> "cover desity" is, I would be glad to include those in the patch as
> well.

Patch applied with this commit message:

	Fix ts_rank_cd() to ignore stripped lexemes
	
	Previously, stripped lexemes got a default location and could be
	considered if mixed with non-stripped lexemes.
	
	BACKWARD INCOMPATIBILITY CHANGE

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
  2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
  2014-01-31 21:22 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-06 18:07   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-11 15:45     ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-02-12 01:49       ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-02-12 14:31         ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 06:29           ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Alexander Hill <alex@hill.net.au>
  2014-03-21 13:43             ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-21 14:45               ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Tom Lane <tgl@sss.pgh.pa.us>
  2014-03-21 22:10                 ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
  2014-03-24 18:37                   ` Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Bruce Momjian <bruce@momjian.us>
@ 2014-03-24 19:49                     ` Bruce Momjian <bruce@momjian.us>
  0 siblings, 0 replies; 12+ messages in thread

From: Bruce Momjian @ 2014-03-24 19:49 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Alexander Hill <alex@hill.net.au>; pgsql-bugs

On Mon, Mar 24, 2014 at 02:37:30PM -0400, Bruce Momjian wrote:
> > OK, thanks.  Updated patch attached.  If Alexander Hill would like to
> > add more C comments to any of the ts*.c files, or docs explaining what
> > "cover density" is, I would be glad to include those in the patch as
> > well.
> 
> Patch applied with this commit message:
> 
> 	Fix ts_rank_cd() to ignore stripped lexemes
> 	
> 	Previously, stripped lexemes got a default location and could be
> 	considered if mixed with non-stripped lexemes.
> 	
> 	BACKWARD INCOMPATIBILITY CHANGE

FYI, I forgot to mention Alex Hill's name in this commit, so I have
added a little docs around cover density and mentioned his name as
author of the previous patch so we can reflect that in the 9.4 release
notes.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2014-03-24 19:49 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02 07:03 BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd alex@hill.net.au
2014-01-31 21:22 ` Bruce Momjian <bruce@momjian.us>
2014-02-06 18:07   ` Alexander Hill <alex@hill.net.au>
2014-02-11 15:45     ` Bruce Momjian <bruce@momjian.us>
2014-02-12 01:49       ` Alexander Hill <alex@hill.net.au>
2014-02-12 14:31         ` Bruce Momjian <bruce@momjian.us>
2014-03-21 06:29           ` Alexander Hill <alex@hill.net.au>
2014-03-21 13:43             ` Bruce Momjian <bruce@momjian.us>
2014-03-21 14:45               ` Tom Lane <tgl@sss.pgh.pa.us>
2014-03-21 22:10                 ` Bruce Momjian <bruce@momjian.us>
2014-03-24 18:37                   ` Bruce Momjian <bruce@momjian.us>
2014-03-24 19:49                     ` Bruce Momjian <bruce@momjian.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox