On Mon, 12 Oct 2009 18:46:02 +0530
Gaini Rajeshwar <raja.rajeshwar2006@gmail.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