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

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

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 Naoko Reeves 2009-10-12 13:52:36 Cascading of trigger execution level
Previous Message Gaini Rajeshwar 2009-10-12 13:41:01 Re: Ranking search results using multiple fields in PostgreSQL fulltext search