pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14552: tsquery converts AND operator into OR when nested inside OR operations
2+ messages / 2 participants
[nested] [flat]

* BUG #14552: tsquery converts AND operator into OR when nested inside OR operations
@ 2017-02-18 00:36 bjorn@eventmy.com
  2017-02-18 01:24 ` Re: BUG #14552: tsquery converts AND operator into OR when nested inside OR operations Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: bjorn@eventmy.com @ 2017-02-18 00:36 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14552
Logged by:          Bjorn Linder
Email address:      bjorn@eventmy.com
PostgreSQL version: 9.4.5
Operating system:   OS 10.11.6
Description:        

Working correctly, no results: 
SELECT ts_rank(to_tsvector('lets eat a cat'), ('fat & bat | rat'::tsquery &&
'cat'::tsquery));
 ts_rank
---------
   1e-20
(1 row)

Should also yield no results:
SELECT ts_rank(to_tsvector('lets eat a fat cat'), ('fat & bat |
rat'::tsquery && 'cat'::tsquery));
  ts_rank
-----------
 0.0991032
(1 row)

Is this intended behavior? Is there a recommended way to nest AND operators
inside OR operations? The relevant documentation looks to be the same for
newer versions so I'm assuming this behavior hasn't been changed between
versions - let me know. Thanks!


-- 
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] 2+ messages in thread

* Re: BUG #14552: tsquery converts AND operator into OR when nested inside OR operations
  2017-02-18 00:36 BUG #14552: tsquery converts AND operator into OR when nested inside OR operations bjorn@eventmy.com
@ 2017-02-18 01:24 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2017-02-18 01:24 UTC (permalink / raw)
  To: bjorn@eventmy.com; +Cc: pgsql-bugs

bjorn@eventmy.com writes:
> Working correctly, no results: 
> SELECT ts_rank(to_tsvector('lets eat a cat'), ('fat & bat | rat'::tsquery &&
> 'cat'::tsquery));
>  ts_rank
> ---------
>    1e-20
> (1 row)

> Should also yield no results:
> SELECT ts_rank(to_tsvector('lets eat a fat cat'), ('fat & bat |
> rat'::tsquery && 'cat'::tsquery));
>   ts_rank
> -----------
>  0.0991032
> (1 row)

> Is this intended behavior?

Don't see what you find surprising about it?  ts_rank() is documented as

	Ranks vectors based on the frequency of their matching lexemes.

The first example has one lexeme that matches the query's lexemes,
the second has two.  It should get a higher ranking.

If you want to know whether the tsvector formally matches the query,
you should be applying the @@ operator.  ts_rank() is not a binary
yes/no thing, it's trying to identify stuff that is more or less
relevant to the query's terms.  At least from the documentation,
I'd suspect it pays no attention to the operators in the query.

In short: the intended use of ts_rank() is for sorting values that
have already passed an @@ match.  It's not a substitute for @@.

			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] 2+ messages in thread


end of thread, other threads:[~2017-02-18 01:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-02-18 00:36 BUG #14552: tsquery converts AND operator into OR when nested inside OR operations bjorn@eventmy.com
2017-02-18 01:24 ` Tom Lane <tgl@sss.pgh.pa.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