Re: [GENERAL] Use full text to rank results higher if they are"closer hit" - Mailing list pgsql-general

From Artur Zakirov
Subject Re: [GENERAL] Use full text to rank results higher if they are"closer hit"
Date
Msg-id 92d35d05-70aa-4f05-19bb-e9ed5d394179@postgrespro.ru
Whole thread Raw
In response to [GENERAL] Use full text to rank results higher if they are "closer hit"  (Thomas Nyberg <tomuxiong@gmx.com>)
Responses Re: [GENERAL] Use full text to rank results higher if they are"closer hit"  (Artur Zakirov <a.zakirov@postgrespro.ru>)
List pgsql-general
On 14.02.2017 18:35, Thomas Nyberg wrote:
>
> Here both 'hello' and 'hello world' are ranked equally highly when
> searching with 'hello'. What I'm wondering is, is there a way within
> postgres to have it match higher to just 'hello' than 'hello world'?
> I.e. something like it slightly down-weights extraneous terms? Of course
> in general I don't know the query or the field strings ahead of time.
>
> Thanks for any help!
>
> Cheers,
> Thomas
>
>

Hello,

try the query:

SELECT s, ts_rank(vector, query) AS rank
FROM t, to_tsvector(s) vector, to_tsquery('hello') query
WHERE query @@ vector;
       s      |   rank
-------------+-----------
  hello       | 0.0607927
  hello world | 0.0303964
(2 rows)

And read about **normalization** in [1]

https://www.postgresql.org/docs/current/static/textsearch-controls.html

--
Artur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] database folder name and tables filenames
Next
From: Artur Zakirov
Date:
Subject: Re: [GENERAL] Use full text to rank results higher if they are"closer hit"