pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ivan E. Panchenko <i.panchenko@postgrespro.ru>
To: pgsql-general@lists.postgresql.org
Subject: Re: How to do phrase search?
Date: Sat, 11 Jul 2020 10:20:40 +0300
Message-ID: <362f19a9-c7a7-c439-0117-4ec287dd404e@postgrespro.ru> (raw)
In-Reply-To: <CANtp6R+MSnoYQ8ALO7cpxxmZtGhyTfoFcUsp35NWQV_KgMuG4w@mail.gmail.com>
References: <CANtp6R+MSnoYQ8ALO7cpxxmZtGhyTfoFcUsp35NWQV_KgMuG4w@mail.gmail.com>

Hello,

On 10.07.2020 21:22, Anto Aravinth wrote:
> Hello,
>
> I have the following table:
>
> so2, which has following column details:
>
> ​
>
> |id, title, posts, body (tsvector). |
>
> And I created the index on the following:
>
> |"so2_pkey" PRIMARY KEY, btree (id)|
>
> |"body" gin (body)|
>
> ​
>
> And I wanted to query on my tsvector with the string: `Is it possible 
> to toggle the visibility of an element`. I tried the following query:
>
If you want phrase search, use the phraseto_tsquery function, like

    phraseto_tsquery( 'Is it possible to toggle the visibility of an 
element')

or

    phraseto_tsquery( 'my_ts_config', 'Is it possible to toggle the 
visibility of an element')

> ​
>
> |SELECT id, ts_rank(body, keywords) AS rank|
>
> |FROM so2,|
>
> |to_tsquery('Is & it & possible & to & toggle & the & visibility & of 
> & an & element')|
>
> |keywords|
>
> |WHERE keywords @@ body ORDER BY rank DESC;|
>
> ​
>
> This give the result in which the "element" string count is large in 
> number, however there is a record which exactly matches the search 
> string, that comes as third in my result. So logically it just checked 
> in my query which word count occurs the most across my body column, 
> which I don't want.
>
> ​
>
> Can I say somehow to postgresql, that I want the pharse search rather 
> than the text spilt up weight in the document. Is it possible to do?
>
> Edit: I tried with `|ts_rank_cd\|` as well. Same result.
>

view thread (2+ messages)

Message-ID: <362f19a9-c7a7-c439-0117-4ec287dd404e@postgrespro.ru>
Permalink:  ../362f19a9-c7a7-c439-0117-4ec287dd404e@postgrespro.ru/
Also on:    postgresql.org/message-id/362f19a9-c7a7-c439-0117-4ec287dd404e@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-general@postgresql.org
  Cc: i.panchenko@postgrespro.ru
  Subject: Re: How to do phrase search?
  In-Reply-To: <362f19a9-c7a7-c439-0117-4ec287dd404e@postgrespro.ru>
  References: <CANtp6R+MSnoYQ8ALO7cpxxmZtGhyTfoFcUsp35NWQV_KgMuG4w@mail.gmail.com> <362f19a9-c7a7-c439-0117-4ec287dd404e@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