pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: nikolajs.arhipovs@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15488: Unexpected behaviour of to_tsverctor and ts_query
Date: Wed, 7 Nov 2018 14:20:55 +0300
Message-ID: <dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru> (raw)
In-Reply-To: <15488-a738bcc48f1af087@postgresql.org>
References: <15488-a738bcc48f1af087@postgresql.org>

Hello,

On 06.11.2018 15:51, PG Bug reporting form wrote:
> I am trying to do prefix search of emails using full text search. Emails
> sometimes contain dot symbols.
> Now, select to_tsquery('simple', 'thing.a:*'); returns a single term as
> expected but
> select to_tsquery('simple', 'the.thing.a:*')  suddenly tokenizes my search
> expression into 'the.thing':* & 'a':*. At the same time select
> to_tsquery('simple', 'the.thing.aa:*'); tokenizes as expected into a single
> term.
> Also select to_tsquery('simple', 'the.thing@gmail.com'); returns a single
> term as expected, but select to_tsquery('simple', 'the.thing@gma:*'); splits
> on @ char and returns two tokens.
> This behavior is not covered in the official documentation.

Yeah, it seems strange, but full text search parser thinks that each 
label of a host should have at least two characters.
In first example it thinks that it is a file name:

=# select * from ts_debug('simple', 'thing.a:*');
  alias |    description    |  token  | dictionaries | dictionary | 
lexemes
-------+-------------------+---------+--------------+------------+-----------
  file  | File or path name | thing.a | {simple}     | simple     | 
{thing.a}
  blank | Space symbols     | :*      | {}           | (null)     | (null)

Next, it thinks that only first two label are only part of host name:

=# select * from ts_debug('simple', 'the.thing.a:*');
    alias   |   description   |   token   | dictionaries | dictionary | 
  lexemes
-----------+-----------------+-----------+--------------+------------+-------------
  host      | Host            | the.thing | {simple}     | simple     | 
{the.thing}
  blank     | Space symbols   | .         | {}           | (null)     | 
(null)
  asciiword | Word, all ASCII | a         | {simple}     | simple     | {a}
  blank     | Space symbols   | :*        | {}           | (null)     | 
(null)

And next is host name:

=# select * from ts_debug('simple', 'the.thing.aa:*');
  alias |  description  |    token     | dictionaries | dictionary | 
lexemes
-------+---------------+--------------+--------------+------------+----------------
  host  | Host          | the.thing.aa | {simple}     | simple     | 
{the.thing.aa}
  blank | Space symbols | :*           | {}           | (null)     | (null)

It seems that the RFC doesn't have such restriction, if I'm not 
mistaken. See:
https://tools.ietf.org/html/rfc1034#section-3.1

And same for emails:

=# select * from ts_debug('simple', 'the.thing@gmail.com');
  alias |  description  |        token        | dictionaries | 
dictionary |        lexemes
-------+---------------+---------------------+--------------+------------+-----------------------
  email | Email address | the.thing@gmail.com | {simple}     | simple 
  | {the.thing@gmail.com}

=# select * from ts_debug('simple', 'the.thing@gmail.c:*');
  alias |    description    |   token   | dictionaries | dictionary | 
lexemes
-------+-------------------+-----------+--------------+------------+-------------
  host  | Host              | the.thing | {simple}     | simple     | 
{the.thing}
  blank | Space symbols     | @         | {}           | (null)     | (null)
  file  | File or path name | gmail.c   | {simple}     | simple     | 
{gmail.c}
  blank | Space symbols     | :*        | {}           | (null)     | (null)

=# select * from ts_debug('simple', 'the.thing@gma:*');
    alias   |   description   |   token   | dictionaries | dictionary | 
  lexemes
-----------+-----------------+-----------+--------------+------------+-------------
  host      | Host            | the.thing | {simple}     | simple     | 
{the.thing}
  blank     | Space symbols   | @         | {}           | (null)     | 
(null)
  asciiword | Word, all ASCII | gma       | {simple}     | simple     | 
{gma}
  blank     | Space symbols   | :*        | {}           | (null)     | 
(null)


It seems that it can be easily fixed, but I'm not sure that it won't 
break something.
If you have such host names only in prefix queries (not in documents 
itself) I may suggest the following workaround:

=# select to_tsvector('simple', 'the.thing@gmail.com') @@ 
'the.thing@gma:*'::tsquery;
  ?column?
----------
  t

-- 
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company




view thread (2+ messages)

Message-ID: <dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru>
Permalink:  ../dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru/
Also on:    postgresql.org/message-id/dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: a.zakirov@postgrespro.ru, nikolajs.arhipovs@gmail.com
  Subject: Re: BUG #15488: Unexpected behaviour of to_tsverctor and ts_query
  In-Reply-To: <dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru>
  References: <15488-a738bcc48f1af087@postgresql.org> <dc4c5f92-0eeb-2d5e-32af-653b80816c31@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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