473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

tsearch2 trigger alternative

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_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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #1
2 2534


Chris Gamache wrote:
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. :) look at tsvector.c:864

numattr = SPI_fnumber(rel->rd_att, trigger->tgargs[i]);
if (numattr == SPI_ERROR_NOATTRIBUTE)
{
funcoid = findFunc(trigger->tgargs[i]);
if (funcoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("could not find function or field \"%s\"",
trigger->tgargs[i])));
continue;
}

If current args (trigger->tgargs[i]) isn't a column name, then it's a function
name. It's simple :)


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:

I didn't work with plpgsql :(

--
Teodor Sigaev E-mail: te****@sigaev.ru

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #2

--- Teodor Sigaev <te****@sigaev.ru> wrote:


Chris Gamache wrote:
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. :)

look at tsvector.c:864

numattr = SPI_fnumber(rel->rd_att, trigger->tgargs[i]);
if (numattr == SPI_ERROR_NOATTRIBUTE)
{
funcoid = findFunc(trigger->tgargs[i]);
if (funcoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("could not find function or field \"%s\"",
trigger->tgargs[i])));
continue;
}

If current args (trigger->tgargs[i]) isn't a column name, then it's a
function
name. It's simple :)


Its like a circuit board to Genghis Kahn... :) I still wouldn't be able to
quickly write my own trigger. It occurrs to me that this might be an
opportunity to properly extend tsearch2, though.

I'm sure that the tsearch2 trigger could detect a tsvector type and allow it to
be inserted without modification. That would solve this problem completely! I
can't think of any practical argument against it. It makes sense that others
besides myself would want to selectively weight columns upon insert without
having to write their own custom trigger in C.

CG

__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Nigel J. Andrews | last post by:
This will be a little vague, it was last night and I can't now do the test in that db (see below) so can't give the exact wording. I seem to remember a report a little while ago about tsearch v2...
1
by: psql-mail | last post by:
I have applied the recent tsearch2 patch and recompiled the tsearch2 module but I am still experiencing the same backend crashes as I previously described. Thanks for any help, Mat GDB...
0
by: konf | last post by:
Well, now I tried to compile with tsearch2. I do in src direcotry: ../configure then change into contrib/tsearch2 and do make (as I read in manual) and I got:
9
by: Pavel Stehule | last post by:
Hello I try tsearch2 within czech environment. It is works fine, but I have two questions. 1. I have words "se", "ve" in my czech stop words. But I get this words in result. Why? Have I...
2
by: Fischer Ulrich | last post by:
Hi I have a problem with the restoring of a database which uses tsearch2. I made a backup as discribed in 'tsearch-v2-intro' on the tsearch2 page. Now i'm trying to restore it into a...
1
by: ˧ÃÍ | last post by:
-----ԭʼÓʼþ----- ·¢¼þÈË: ˧ÃÍ ·¢ËÍʱ¼ä: 2004Äê3ÔÂ3ÈÕ 10:41 ÊÕ¼þÈË: 'pgsql-hackers@postgresql.org' Ö÷Ìâ: docs on tsearch2 hi all Are there any other docs about tsearch2 except for the 3...
0
by: Markus Wollny | last post by:
Hi! Sorry to bother you, but I just don't know how to get tsearch2 configured correctly for my setup. I've got a 7.4.3 database-cluster initdb'ed with de_DE@euro as locale, the database is with...
3
by: Marcel Boscher | last post by:
Hello everybody, i tried to "J.U.S.T" install the FullTextSearchTool tsearch2 under the guidiance of : http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/...
2
by: Net Virtual Mailing Lists | last post by:
Hello, If I have a rule like this: CREATE OR REPLACE RULE sometable_update AS ON UPDATE TO table2 DO UPDATE cache SET updated_dt=NULL WHERE tablename='sometable'; CREATE OR REPLACE RULE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.