Re: Ranking search results using multiple fields in PostgreSQL fulltext search - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject Re: Ranking search results using multiple fields in PostgreSQL fulltext search
Date
Msg-id 20091012155624.5f9fde53@dawn.webthatworks.it
Whole thread Raw
In response to Re: Ranking search results using multiple fields in PostgreSQL fulltext search  (Gaini Rajeshwar <raja.rajeshwar2006@gmail.com>)
Responses Re: Ranking search results using multiple fields in PostgreSQL fulltext search
List pgsql-general
On Mon, 12 Oct 2009 19:11:01 +0530
Gaini Rajeshwar <raja.rajeshwar2006@gmail.com> wrote:

> I think you misunderstood my question. let me give clear idea
> about what i need.
>
> I am using PostgreSQL fulltext search (tsearch2) feature to
> implement searching on database. From readings i came to know that
> we can give weights to different fields in database something like
> this:
>
> *setweight(to_tsvector(title),'A')*
>
> Where 'A' is weight given to field title. i can give weights to
> other fields in the same way. Where the weights 'A', 'B', 'C', 'D'
> are in will be in the following order *A > B > C > D* according to
> defalut fulltext search configuration.
>
> We can rank the search results using ts_rank function something
> like this,
>
> *ts_rank(tsv_title,ts_query('this is my search text'))*
> **
> But, i want to rank these reults not only based on just title, but
> also using other fields like summary etc.
> Is there a way around to do this?

if you concatenate your fields with different weight in the *same*
ts_vector, ranking will take into account your weight...

Someone more knowledgeable than me chose how to use weight to give a
reasonable ranking.

Of course if you've field a, b and c and you want to search in a and
b only, you'll have to concatenate just a and b.

If you need different assortment in fields groups... you'll have to
add some extra redundancy if you plan to store precomputed
ts_vectors for each record.

If you need to search "separately" in different fields
(eg. title ~ 'gino' AND summary ~ 'pino')
you just need to weight the input query as well

inputquery := setweight(cfg, inputtitle, 'A', '&');
inputquery := inputquery && setweight(cfg, inputsummary, 'B', '&');

...



--
Ivan Sergio Borgonovo
http://www.webthatworks.it


pgsql-general by date:

Previous
From: Ivan Sergio Borgonovo
Date:
Subject: Re: Ranking search results using multiple fields in PostgreSQL fulltext search
Next
From: Gaini Rajeshwar
Date:
Subject: Re: Ranking search results using multiple fields in PostgreSQL fulltext search