[SOLVED] C function to create tsquery not working

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: [SOLVED] C function to create tsquery not working
Date: 2010-02-12 09:21:46
Message-ID: 20100212102146.77a485a3@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 11 Feb 2010 20:11:54 +0100
Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> wrote:

> I'm still having trouble making this work:

> http://pgsql.privatepaste.com/14a6d3075e

Finally I got it working, not the above version anyway...

CREATE OR REPLACE FUNCTION tsvector_to_tsquery(IN tsv tsvector, op
IN char(1), weights IN varchar(4), maxpos IN smallint
)
RETURNS tsquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;

There were some small errors, but the main one was setting
SET_VARSIZE passing the pointer to the query in spite of the query.

I'll need some smaller help to polish everything.

It is a small work but there was someone on the list that showed
some interest and it may be a nice simple helper for tsearch.

What would be the right place to advertise it and make it available?

To sum it up... I wrote 2 functions:
1 takes a tsvector and return it as a setof record text, int[], int[]
2 takes a tsvector, filter it according to weights and maximum
position and return a | or & tsquery

The first is just for "debugging" or to be able to build more
complicated tsqueries in your preferred language.

The second can come handy to look for text similarity skipping to
compute tsvectors twice.

create or replace function similar(_id int,
out id int, out title text) returns setof record as
$$
declare
tsvin tsvector;
tsq tsquery;
begin
select into tsvin from table where id = _id;
tsq := tsvector_to_tsquery(
tsvin, '|', 'AB', 100);
return query
select t.id, t.title from table t where
t.tsv @@ tsq
;
return;
end;
$$ language plpgsql stable;

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2010-02-12 11:46:35 Re: Function that creates a custom (temporary) table AND returns a pointer to it = impossible in pg?
Previous Message Jasen Betts 2010-02-12 09:13:54 Re: PHP and PostgreSQL boolean data type