Tsearch2 comes with its own tsearch2 trigger function. You pass column names to
it, and it puts a vanilla tsvector into the column named in TG_ARGV[0]. 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 using plpgsql, 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_ts vector(substr($ 1,1,strpos($1,' ',''))),''C'') ||
to_tsvector(sub str($1,strpos($ 1,'','')+1,leng th($1)));' language 'sql';
so...
Plain:
select to_tsvector('Ei nstein, Albert');
to_tsvector
-------------------------
'albert':2 'einstein':1
Weighted:
select name_vector('Ei nstein, 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.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
it, and it puts a vanilla tsvector into the column named in TG_ARGV[0]. 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 using plpgsql, 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_ts vector(substr($ 1,1,strpos($1,' ',''))),''C'') ||
to_tsvector(sub str($1,strpos($ 1,'','')+1,leng th($1)));' language 'sql';
so...
Plain:
select to_tsvector('Ei nstein, Albert');
to_tsvector
-------------------------
'albert':2 'einstein':1
Weighted:
select name_vector('Ei nstein, 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.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Comment