Re: Question about fulltext search and to_tsvector function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mike Christensen <imaudi(at)comcast(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question about fulltext search and to_tsvector function
Date: 2008-10-17 04:02:33
Message-ID: 8030.1224216153@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Christensen <imaudi(at)comcast(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-10-17 04:04:17 Re: Question about NOT NULL and default values.
Previous Message Stephan Szabo 2008-10-17 04:01:39 Re: Question about NOT NULL and default values.