Skip site navigation (1) Skip section navigation (2)

tsearch2 trigger alternative

From: Chris Gamache <cgg007(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: tsearch2 trigger alternative
Date: 2004-02-24 18:58:06
Message-ID: 20040224185806.51777.qmail@web13802.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-performancepgsql-sqlpgsql-www
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

In response to

pgsql-performance by date

Next:From: Christopher BrowneDate: 2004-02-24 19:12:54
Subject: Re: [PERFORMANCE] slow small delete on large table
Previous:From: Ed L.Date: 2004-02-24 18:36:08
Subject: Re: [PERFORMANCE] slow small delete on large table

pgsql-www by date

Next:From: Robert TreatDate: 2004-02-24 21:48:49
Subject: Re: [HACKERS] [SQL] Materialized View Summary
Previous:From: Hans-Jürgen SchönigDate: 2004-02-24 17:40:25
Subject: Re: [HACKERS] [SQL] Materialized View Summary

pgsql-hackers by date

Next:From: Shelby CainDate: 2004-02-24 19:58:56
Subject: select statement against pg_stats returns inconsistent data
Previous:From: Hans-Jürgen SchönigDate: 2004-02-24 17:40:25
Subject: Re: [HACKERS] [SQL] Materialized View Summary

pgsql-sql by date

Next:From: Robert TreatDate: 2004-02-24 21:48:49
Subject: Re: [HACKERS] [SQL] Materialized View Summary
Previous:From: Hans-Jürgen SchönigDate: 2004-02-24 17:40:25
Subject: Re: [HACKERS] [SQL] Materialized View Summary

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group