websearch_to_tsquery() and handling of ampersand characters insidedouble quotes - Mailing list pgsql-general

From Alastair McKinley
Subject websearch_to_tsquery() and handling of ampersand characters insidedouble quotes
Date
Msg-id DB6PR0202MB290450F7668104992B9D6F3CE3940@DB6PR0202MB2904.eurprd02.prod.outlook.com
Whole thread Raw
List pgsql-general
Hi all,

I have recently discovered an unexpected difference in behaviour using websearch_to_tsquery() with quoted strings containing ampersands.

These two queries are equivalent without surrounding double quotes

select websearch_to_tsquery('something and another') = websearch_to_tsquery('something & another');
 ?column?
----------
 t
(1 row)

select websearch_to_tsquery('something and another');
 websearch_to_tsquery
----------------------
 'someth' & 'anoth'
(1 row)


With surrounding double quotes they produce subtly different queries, with different positional information.


 select websearch_to_tsquery('"something and another"') = websearch_to_tsquery('"something & another"');
 ?column?
----------
 f
(1 row)


select websearch_to_tsquery('"something and another"');
 websearch_to_tsquery
----------------------
 'someth' <2> 'anoth'
(1 row)

select websearch_to_tsquery('"something & another"');
 websearch_to_tsquery
----------------------
 'someth' <-> 'anoth'
(1 row)

I imagine the difference is due to the ts_vector type recording different information for the underlying strings.

select to_tsvector('something & another');
     to_tsvector      
----------------------
 'anoth':2 'someth':1
(1 row)

chimera=# select to_tsvector('something and another');
     to_tsvector      
----------------------
 'anoth':3 'someth':1
(1 row)


This leads to quite different search results and my current workaround is to suggest to users to do both searches with an OR.  Is this the right solution?

Best regards,

Alastair

pgsql-general by date:

Previous
From: Alastair McKinley
Date:
Subject: Re: websearch_to_tsquery() and apostrophe inside double quotes
Next
From: Stephen Frost
Date:
Subject: Re: Is my lecturer wrong about PostgreSQL? I think he is!