Re: Ranking search results using multiple fields in PostgreSQL fulltext search

From: Gaini Rajeshwar <raja(dot)rajeshwar2006(at)gmail(dot)com>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Ranking search results using multiple fields in PostgreSQL fulltext search
Date: 2009-10-12 14:32:16
Message-ID: 56b36eb60910120732t1dafbbc0id9eac2f8af1ae066@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 12, 2009 at 7:26 PM, Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it
> wrote:

> On Mon, 12 Oct 2009 19:11:01 +0530
> Gaini Rajeshwar <raja(dot)rajeshwar2006(at)gmail(dot)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...
>
yes, ranking will take into account. but how can we specify just *one field
at the time of searching* and specify *all the fields at the time of
ranking?*

> 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', '&');
>
I didn't understand why did u use '&' operator in setweight function. is
that going to help in any way?

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Teodor Sigaev 2009-10-12 15:07:33 Re: Re: [GENERAL] contrib/plantuner - enable PostgreSQL planner hints
Previous Message Ivan Sergio Borgonovo 2009-10-12 14:32:06 Re: Ranking search results using multiple fields in PostgreSQL fulltext search