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 13:56:55
Message-ID: 56b36eb60910120656x14238e4axd17a4bf01b1b9d84@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ivan,
If i create a tsvector as you mentioned with concatenation operator, my
search query will search in any of these fields which are concatenated in my
tsvector.
For example, if i create tsvector like this,
UPDATE document_table SET search_col =
setweight(to_tsvector(coalesce(title,'')), 'A') ||
setweight(to_tsvector(coalesce(summary,'')), 'B'));

and do a query like this
select title, ts_rank(search_col, to_tsquery('this is my text search') AS
rank
FROM search_col @@ to_tsvector('this & is & my & text & search')
ORDER BY rank DESC
the above query will search in title and summary and will give me the
results. But i dont want in that way.When a user wants to search in title,
it should just search in title but the results should be ranked based on *
title* and *summary* field.
On Mon, Oct 12, 2009 at 7:16 PM, Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it
> wrote:

> On Mon, 12 Oct 2009 18:46:02 +0530
> Gaini Rajeshwar <raja(dot)rajeshwar2006(at)gmail(dot)com> 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"
>
> http://www.postgresql.org/docs/current/interactive/textsearch-controls.html
>
> Basically, as you can read in the docs:
> - you create a ts_vector concatenating and giving a weight the
> various fields.
> - then you compare your ts_vector with
> plainto_tsquery(config, yourinput) @@
> yourpreviouslycomputedts_vector
>
> and order by ts_rank(yourpreviouslycomputedts_vector, yourinput)
> (or ts_rank_cd)
>
>
> --
> Ivan Sergio Borgonovo
> http://www.webthatworks.it
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message utsav 2009-10-12 14:04:40 ERROR: simple_heap_delete: tuple already updated by self
Previous Message Ivan Sergio Borgonovo 2009-10-12 13:56:24 Re: Ranking search results using multiple fields in PostgreSQL fulltext search