How to do phrase search?

From: Anto Aravinth <anto(dot)aravinth(dot)cse(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: How to do phrase search?
Date: 2020-07-10 18:22:23
Message-ID: CANtp6R+MSnoYQ8ALO7cpxxmZtGhyTfoFcUsp35NWQV_KgMuG4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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:

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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-07-10 19:47:00 Re: PG Admin 4
Previous Message rwest 2020-07-10 16:36:26 Re: PG Admin 4