Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qpAJJ-004crX-Vn for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2023 16:37:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qpAJG-000Zwb-72 for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2023 16:37:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qpAJF-000ZwS-SF for pgsql-bugs@lists.postgresql.org; Sat, 07 Oct 2023 16:37:46 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qpAJ9-000Uqv-PT for pgsql-bugs@lists.postgresql.org; Sat, 07 Oct 2023 16:37:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 397GbbB93149022; Sat, 7 Oct 2023 12:37:37 -0400 From: Tom Lane To: Patrick Peralta cc: Laurenz Albe , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18149: Incorrect lexeme for english token "proxy" In-reply-to: References: <18149-936d14e6fc76ca61@postgresql.org> <25d0bf34e0f7e0d9f3455e1b7adaf5a5aee810e1.camel@cybertec.at> <3123965.1696688336@sss.pgh.pa.us> Comments: In-reply-to Patrick Peralta message dated "Sat, 07 Oct 2023 12:07:18 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3149020.1696696657.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 07 Oct 2023 12:37:37 -0400 Message-ID: <3149021.1696696657@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Patrick Peralta writes: > However I ran into an anomaly with this query: > # SELECT to_tsvector('english', 'CLOUD-PROXY-SEP19-T1-254--1695167380256= ') > @@ to_tsquery('english','cloud-proxy:*'); > ?column? > ---------- > f > (1 row) Hmm. Investigating that a bit: regression=3D# select * from ts_debug('english', 'cloud-proxy'); alias | description | token | dictio= naries | dictionary | lexemes = -----------------+---------------------------------+-------------+--------= --------+--------------+--------------- asciihword | Hyphenated word, all ASCII | cloud-proxy | {englis= h_stem} | english_stem | {cloud-proxi} hword_asciipart | Hyphenated word part, all ASCII | cloud | {englis= h_stem} | english_stem | {cloud} blank | Space symbols | - | {} = | | = hword_asciipart | Hyphenated word part, all ASCII | proxy | {englis= h_stem} | english_stem | {proxi} (4 rows) regression=3D# select * from ts_debug('english', 'CLOUD-PROXY-SEP19-T1-254= --1695167380256'); alias | description | token= | dictionaries | dictionary | lexemes = -----------------+------------------------------------------+-------------= ---------+----------------+--------------+------------------------ numhword | Hyphenated word, letters and digits | CLOUD-PROXY-= SEP19-T1 | {simple} | simple | {cloud-proxy-sep19-t1} hword_asciipart | Hyphenated word part, all ASCII | CLOUD = | {english_stem} | english_stem | {cloud} blank | Space symbols | - = | {} | | = hword_asciipart | Hyphenated word part, all ASCII | PROXY = | {english_stem} | english_stem | {proxi} blank | Space symbols | - = | {} | | = hword_numpart | Hyphenated word part, letters and digits | SEP19 = | {simple} | simple | {sep19} blank | Space symbols | - = | {} | | = hword_numpart | Hyphenated word part, letters and digits | T1 = | {simple} | simple | {t1} blank | Space symbols | - = | {} | | = uint | Unsigned integer | 254 = | {simple} | simple | {254} blank | Space symbols | - = | {} | | = int | Signed integer | -16951673802= 56 | {simple} | simple | {-1695167380256} (12 rows) So the difficulty is that (a) the default TS parser doesn't break down this multiply-hyphenated word quite the way you'd hoped, and (b) fragments classified as numhword aren't passed through the english_stem dictionary at all. Also, (c) I'm doubtful that the snowball stemmer would have converted cloud-proxy-sep19-t1 to cloud-proxi-sep19-t1; but it didn't get the chance anyway. While (b) would be easy to address with a custom TS configuration, (a) and (c) can't be fixed without getting your hands dirty in C code. Is there any chance of adjusting the notation you're dealing with here? I get sane-looking results from, for example, regression=3D# select to_tsvector('english', 'CLOUD-PROXY--SEP19-T1-254--1= 695167380256'); to_tsvector = = --------------------------------------------------------------------------= -------------------- '-1695167380256':8 '254':7 'cloud':2 'cloud-proxi':1 'proxi':3 'sep19':5 = 'sep19-t1':4 't1':6 (1 row) If that data format is being imposed on you then I'm not seeing a good solution without custom C code. I'd be inclined to try to make the parser generate all of "cloud-proxy-sep19-t1", "cloud-proxy-sep19", "cloud-proxy" from this input, but a custom TS parser is kind of a high bar to clear. regards, tom lane