Re: Question about fulltext search and to_tsvector function - Mailing list pgsql-general

From Tom Lane
Subject Re: Question about fulltext search and to_tsvector function
Date
Msg-id 8030.1224216153@sss.pgh.pa.us
Whole thread Raw
In response to Re: Question about fulltext search and to_tsvector function  (Mike Christensen <imaudi@comcast.net>)
List pgsql-general
Mike Christensen <imaudi@comcast.net> writes:
> This is exactly what you would do as well?  I just want to make sure
> this isn't considered a hack..

It certainly works.  What the docs seem to recommend though is
concatenating the *output* of to_tsvector applied to each field,
along the lines of

   setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
   setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'D');

(cf. section 12.4.3 in the 8.3 docs).  I'm not sure about whether this
is better or worse from a micro-optimization speed point of view, but
the reason to do it this way is you can attach different weights to
words from different fields, as illustrated above.  That can come in
handy in future searching.

(Note that || applied to tsvectors isn't really just simple
concatenation, but that's the operator name that was chosen.)

            regards, tom lane

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Question about NOT NULL and default values.
Next
From: "Scott Marlowe"
Date:
Subject: Re: Question about NOT NULL and default values.