Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ju9oW-0006bA-0H for pgsql-general@arkaria.postgresql.org; Sat, 11 Jul 2020 07:20:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ju9oV-0006CE-03 for pgsql-general@arkaria.postgresql.org; Sat, 11 Jul 2020 07:20:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ju9oU-0006C5-K0 for pgsql-general@lists.postgresql.org; Sat, 11 Jul 2020 07:20:46 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ju9oQ-0000cp-LR for pgsql-general@lists.postgresql.org; Sat, 11 Jul 2020 07:20:45 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id E4FF221C75EC for ; Sat, 11 Jul 2020 10:20:41 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.43.235] (host-219-159-66-217.spbmts.ru [217.66.159.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 7864021C75D2 for ; Sat, 11 Jul 2020 10:20:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1594452041; bh=5M80xtyF9N7L4n50ggyuA40If5TtZGXj80Lrr95AS5Q=; h=Subject:To:References:From:Date:In-Reply-To; b=cu3XL5TFKrlPUaJzF0iwFpmKWCAcRonONB/RMj1jKJZF1bY/w28z7eQAyoVBHPUig bXdu4rleuEQm7jJctoZONxuKSpp3/SMnRLh4uF9EL7w1FnR5DD3UI5W5KWX3TzllDN VtZ3UOjBq9J1cZgW0aCz+yD7hByfL3Ob9w8t4Aq4= Subject: Re: How to do phrase search? To: pgsql-general@lists.postgresql.org References: From: "Ivan E. Panchenko" Message-ID: <362f19a9-c7a7-c439-0117-4ec287dd404e@postgrespro.ru> Date: Sat, 11 Jul 2020 10:20:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------E19BDE14F61164763E5B15EF" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------E19BDE14F61164763E5B15EF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. > --------------E19BDE14F61164763E5B15EF Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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.


--------------E19BDE14F61164763E5B15EF--