Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKLtR-0003q6-0h for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Nov 2018 11:21:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gKLtM-0007uu-Nb for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Nov 2018 11:21:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKLtM-0007uk-Cn for pgsql-bugs@lists.postgresql.org; Wed, 07 Nov 2018 11:21:00 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gKLtJ-0003Z5-Ix for pgsql-bugs@lists.postgresql.org; Wed, 07 Nov 2018 11:20:59 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 02B3F21C248F; Wed, 7 Nov 2018 14:20:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id C75CD21C2486; Wed, 7 Nov 2018 14:20:55 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1541589655; bh=Fodqcz3cEYJUI3gEl71xcq+Qjt/7KhLf9GKMzPI50FA=; h=Subject:To:References:From:Date:In-Reply-To; b=C8nfD5DqrT0yCIMvEFWd8iW7QDfJhfp93/GVPYL9GEJJbVsAsNIzojNNTHHPA+p2f sGHdbFFJVbH6W8fiV12DqfJMWUjIQrKzIDPTMghi4nh7LT6DL8KBhhHyMTSRhWShmL jQRYGJDuWfJkrTU49pmf+zkSn/38JvZcBJjSwVwM= Subject: Re: BUG #15488: Unexpected behaviour of to_tsverctor and ts_query To: nikolajs.arhipovs@gmail.com, pgsql-bugs@lists.postgresql.org References: <15488-a738bcc48f1af087@postgresql.org> From: Arthur Zakirov Message-ID: Date: Wed, 7 Nov 2018 14:20:55 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <15488-a738bcc48f1af087@postgresql.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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