pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedwebsearch_to_tsquery() and apostrophe inside double quotes
3+ messages / 2 participants
[nested] [flat]
* websearch_to_tsquery() and apostrophe inside double quotes
@ 2019-10-10 11:42 Alastair McKinley <a.mckinley@analyticsengines.com>
2019-10-10 13:35 ` Re: websearch_to_tsquery() and apostrophe inside double quotes Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Alastair McKinley @ 2019-10-10 11:42 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi all,
I am a little confused about what us being generated by websearch_to_tsquery() in the case of an apostrophe inside double quotes.
Here is an example of searching for a name containing an apostrophe.
The following works as expected:
select to_tsvector('peter o''toole') @@ websearch_to_tsquery('peter o''toole');
?column?
----------
t
(1 row)
When the name is in double quotes, the search fails:
select to_tsvector('peter o''toole') @@ websearch_to_tsquery('"peter o''toole"');
?column?
----------
f
(1 row)
In the first case, websearch_to_tsquery() returns:
select websearch_to_tsquery('peter o''toole');
websearch_to_tsquery
------------------------
'peter' & 'o' & 'tool'
(1 row)
which makes sense to me.
In the second case websearch_to_tsquery() returns something that I can't quite understand:
select websearch_to_tsquery('"peter o''toole"');
websearch_to_tsquery
------------------------------
'peter' <-> ( 'o' & 'tool' )
(1 row)
I am not quite sure what text this will actually match?
Best regards,
Alastair
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: websearch_to_tsquery() and apostrophe inside double quotes
2019-10-10 11:42 websearch_to_tsquery() and apostrophe inside double quotes Alastair McKinley <a.mckinley@analyticsengines.com>
@ 2019-10-10 13:35 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-10 14:10 ` Re: websearch_to_tsquery() and apostrophe inside double quotes Alastair McKinley <a.mckinley@analyticsengines.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2019-10-10 13:35 UTC (permalink / raw)
To: Alastair McKinley <a.mckinley@analyticsengines.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; teodor@sigaev.ru
Alastair McKinley <a.mckinley@analyticsengines.com> writes:
> I am a little confused about what us being generated by websearch_to_tsquery() in the case of an apostrophe inside double quotes.
> ...
> select websearch_to_tsquery('"peter o''toole"');
> websearch_to_tsquery
> ------------------------------
> 'peter' <-> ( 'o' & 'tool' )
> (1 row)
> I am not quite sure what text this will actually match?
I believe it's impossible for that to match anything :-(.
It would require 'o' and 'tool' to match the same lexeme
(one immediately after a 'peter') which of course is impossible.
The underlying tsvector type seems to treat the apostrophe the
same as whitespace; it separates 'o' and 'toole' into
distinct words:
# select to_tsvector('peter o''toole');
to_tsvector
--------------------------
'o':2 'peter':1 'tool':3
(1 row)
So it seems to me that this is a bug: websearch_to_tsquery
should also treat "'" like whitespace. There's certainly
not anything in its documentation that suggests it should
treat "'" specially. If it didn't, you'd get
# select websearch_to_tsquery('"peter o toole"');
websearch_to_tsquery
----------------------------
'peter' <-> 'o' <-> 'tool'
(1 row)
which would match this tsvector.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: websearch_to_tsquery() and apostrophe inside double quotes
2019-10-10 11:42 websearch_to_tsquery() and apostrophe inside double quotes Alastair McKinley <a.mckinley@analyticsengines.com>
2019-10-10 13:35 ` Re: websearch_to_tsquery() and apostrophe inside double quotes Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-10-10 14:10 ` Alastair McKinley <a.mckinley@analyticsengines.com>
0 siblings, 0 replies; 3+ messages in thread
From: Alastair McKinley @ 2019-10-10 14:10 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; teodor@sigaev.ru <teodor@sigaev.ru>
Hi Tom,
Thank you for looking at this. You are right I couldn't find anything in the docs that would explain this.
I can't think of any rationale for producing a query like this so it does look like a bug.
Best regards,
Alastair
________________________________
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: 10 October 2019 14:35
To: Alastair McKinley <a.mckinley@analyticsengines.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; teodor@sigaev.ru <teodor@sigaev.ru>
Subject: Re: websearch_to_tsquery() and apostrophe inside double quotes
Alastair McKinley <a.mckinley@analyticsengines.com> writes:
> I am a little confused about what us being generated by websearch_to_tsquery() in the case of an apostrophe inside double quotes.
> ...
> select websearch_to_tsquery('"peter o''toole"');
> websearch_to_tsquery
> ------------------------------
> 'peter' <-> ( 'o' & 'tool' )
> (1 row)
> I am not quite sure what text this will actually match?
I believe it's impossible for that to match anything :-(.
It would require 'o' and 'tool' to match the same lexeme
(one immediately after a 'peter') which of course is impossible.
The underlying tsvector type seems to treat the apostrophe the
same as whitespace; it separates 'o' and 'toole' into
distinct words:
# select to_tsvector('peter o''toole');
to_tsvector
--------------------------
'o':2 'peter':1 'tool':3
(1 row)
So it seems to me that this is a bug: websearch_to_tsquery
should also treat "'" like whitespace. There's certainly
not anything in its documentation that suggests it should
treat "'" specially. If it didn't, you'd get
# select websearch_to_tsquery('"peter o toole"');
websearch_to_tsquery
----------------------------
'peter' <-> 'o' <-> 'tool'
(1 row)
which would match this tsvector.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2019-10-10 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 11:42 websearch_to_tsquery() and apostrophe inside double quotes Alastair McKinley <a.mckinley@analyticsengines.com>
2019-10-10 13:35 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-10 14:10 ` Alastair McKinley <a.mckinley@analyticsengines.com>
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