Phrase search distance syntax

Started by Bruce Momjianover 9 years ago4 messages
#1Bruce Momjian
bruce@momjian.us

Sorry to be asking another phrase search syntax question, and so close
to final release, but ...

Why does the phrase distance operator assume <1> means adjacent words,
and not <0>. (FYI, <-> is the same as <1>.)

For example:

select to_tsvector('park a a house') @@ to_tsquery('park <3> house');

seems like it would be more logical as <2>, meaning two lexems between
the words.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+                     Ancient Roman grave inscription +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Teodor Sigaev
teodor@sigaev.ru
In reply to: Bruce Momjian (#1)
Re: Phrase search distance syntax

Sorry to be asking another phrase search syntax question, and so close
to final release, but ...

Really close...

Why does the phrase distance operator assume <1> means adjacent words,
and not <0>. (FYI, <-> is the same as <1>.)

Because
1 it is a result of subtruction of word's positions
2 <0> could be used as special case like a word with two infinitives:
# create text search dictionary xx (template = 'ispell',
DictFile='ispell_sample', AffFile='ispell_sample');
# alter text search configuration english ALTER MAPPING FOR asciiword WITH xx,
english_stem;

# select to_tsvector('english', 'bookings');
to_tsvector
----------------------
'book':1 'booking':1

# select to_tsvector('english', 'bookings') @@ 'book <0> booking';
?column?
----------
t
(1 row)

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Bruce Momjian
bruce@momjian.us
In reply to: Teodor Sigaev (#2)
Re: Phrase search distance syntax

On Fri, Sep 23, 2016 at 05:07:26PM +0300, Teodor Sigaev wrote:

Sorry to be asking another phrase search syntax question, and so close
to final release, but ...

Really close...

Why does the phrase distance operator assume <1> means adjacent words,
and not <0>. (FYI, <-> is the same as <1>.)

Because
1 it is a result of subtruction of word's positions
2 <0> could be used as special case like a word with two infinitives:
# create text search dictionary xx (template = 'ispell',
DictFile='ispell_sample', AffFile='ispell_sample');
# alter text search configuration english ALTER MAPPING FOR asciiword WITH
xx, english_stem;

# select to_tsvector('english', 'bookings');
to_tsvector
----------------------
'book':1 'booking':1

# select to_tsvector('english', 'bookings') @@ 'book <0> booking';
?column?
----------
t
(1 row)

OK, thanks. I just found it as unusual.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+                     Ancient Roman grave inscription +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Teodor Sigaev (#2)
Re: Phrase search distance syntax

Teodor Sigaev <teodor@sigaev.ru> writes:

Why does the phrase distance operator assume <1> means adjacent words,
and not <0>. (FYI, <-> is the same as <1>.)

Because
1 it is a result of subtruction of word's positions
2 <0> could be used as special case like a word with two infinitives:

This is actually documented, in 12.1.2:

A special case that's sometimes useful is that <0> can be used to
require that two patterns match the same word.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers