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

From: Gaini Rajeshwar <raja(dot)rajeshwar2006(at)gmail(dot)com>
To: rod(at)iol(dot)ie
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Ranking search results using multiple fields in PostgreSQL fulltext search
Date: 2009-10-12 13:41:01
Message-ID: 56b36eb60910120641x40b958d3t272a82044447f72b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

On Mon, Oct 12, 2009 at 6:53 PM, Raymond O'Donnell <rod(at)iol(dot)ie> wrote:

> On 12/10/2009 14:16, Gaini Rajeshwar wrote:
> > Hi,
> > is there a way to rank the search results based on multiple fields in
> > postgreSQL?
> > For example,
> > i have *title*, *abstract*, *summary*, *body* as fields/columns in my
> > database. When user searches on *title*, i want to rank the results based
> on
> > *title* field as well as *summary* field, where importance(summary) >
> > importance(title). But the results should be exactly matching the terms
> in
> > "title" rather than "title" OR "summary"
> >
>
> Hoe do you define "importance"?
>
> You can order the results alphabetically/numerically on as many columns
> as you like - for example,
>
> select ....
> where title = ....
> order by title, summary
>
> will order the results on title first, then summary... though you
> probably know this and I'm misunderstanding what you need.
>
> A little more detail will help.
>
> Ray.
>
> ------------------------------------------------------------------
> Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
> rod(at)iol(dot)ie
> Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
> ------------------------------------------------------------------
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-10-12 13:46:13 Re: Ranking search results using multiple fields in PostgreSQL fulltext search
Previous Message Raymond O'Donnell 2009-10-12 13:33:16 Re: Ranking search results using multiple fields in PostgreSQL fulltext search