Range phrase operator in tsquery

From: Aleksandr Parfenov <a(dot)parfenov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Range phrase operator in tsquery
Date: 2018-04-27 11:03:07
Message-ID: 20180427140307.038769f4@asp437-24-g082ur
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

Hello hackers,

Nowadays, phrase operator in Postgres FTS supports only exact match of
the distance between two words. It is sufficient for a search of
simple/exact phrases, but in some cases exact distance is unknown and we
want to words be close enough. E.g. it may help to search phrases with
additional words in the middle of the phrase ("long, narrow, plastic
brush" vs "long brush")

Proposed patch adds ability to use ranges in phrase operator for
mentioned cases. Few examples:

'term1 <4,10> term2'::tsquery -- Distance between term1 and term2 is
-- at least 4 and no greater than 10
'term1 <,10> term2'::tsquery -- Distance between term1 and term2 is
-- no greater than 10
'term1 <4,> term2'::tsquery -- Distance between term1 and term2 is
-- at least 4

In addition, negative distance is supported and means reverse order of
the words. For example:
'term1 <4,10> term2'::tsquery = 'term2 <-10,-4> term1'::tsquery
'term1 <,10> term2'::tsquery = 'term2 <-10,> term1'::tsquery
'term1 <4,> term2'::tsquery = 'term2 <,-4> term1'::tsquery

Negative distance support introduced to use it for AROUND operator
mentioned in websearch_to_tsquery[1]. In web search query language
AROUND(N) does a search for words within given distance N in
both forward and backward direction and it can be represented as <-N,N>
range phrase operator.

[1]
https://www.postgresql.org/message-id/flat/fe931111ff7e9ad79196486ada79e268(at)postgrespro(dot)ru

--
Aleksandr Parfenov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company

Attachment Content-Type Size
0001-range_phrase_operator_v1.patch text/x-patch 42.8 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruno Lavoie 2018-04-27 11:39:06 Fwd: Failed rpm package signature checks with reposync
Previous Message Ashutosh Bapat 2018-04-27 10:25:25 Re: Problem while updating a foreign table pointing to a partitioned table on foreign server