X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 83E9BD1CCD7 for ; Tue, 24 Feb 2004 18:58:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 46686-10 for ; Tue, 24 Feb 2004 14:58:09 -0400 (AST) Received: from web13802.mail.yahoo.com (web13802.mail.yahoo.com [216.136.175.12]) by svr1.postgresql.org (Postfix) with SMTP id 7764CD1BACA for ; Tue, 24 Feb 2004 14:58:07 -0400 (AST) Message-ID: <20040224185806.51777.qmail@web13802.mail.yahoo.com> Received: from [216.173.173.66] by web13802.mail.yahoo.com via HTTP; Tue, 24 Feb 2004 10:58:06 PST Date: Tue, 24 Feb 2004 10:58:06 -0800 (PST) From: Chris Gamache Reply-To: cgg007@yahoo.com Subject: tsearch2 trigger alternative To: pgsql-sql@postgresql.org In-Reply-To: <200402241711.20947.dev@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/340 X-Sequence-Number: 17030 Tsearch2 comes with its own tsearch2 trigger function. You pass column names to it, and it puts a vanilla tsvector into the column names in TG_ARGV[0] (zero based, yes?). Not only can you pass column names to it, but you can pass simple functions to it as well. This is magical to me. :) I'm trying to figure out how to do the same thing, except instead of returning a vanilla tsvector, I want to return a specially weighted tsvector. I've created a function that can do this: create or replace function name_vector (text) returns tsvector as ' select setweight(to_tsvector(substr($1,1,strpos($1,'',''))),''C'') || to_tsvector(substr($1,strpos($1,'','')+1,length($1))); ' language 'sql'; so... Plain: select to_tsvector('Einstein, Albert'); to_tsvector ------------------------- 'albert':2 'einstein':1 Weighted: select name_vector('Einstein, Albert'); name_vector -------------------------- 'albert':2 'einstein':1C Now, to somehow package that into a magical trigger function... All the examples for creating trigger functions that I've found use static column names, NEW and OLD ... I would like to create a generic trigger function, as the tsearch2 trigger function does, to return the specially weighted tsvector. Its like a lighter to a caveman. Can anyone lend a hand? CG __________________________________ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools