[SOLVED] C function to create tsquery not working

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема [SOLVED] C function to create tsquery not working
Дата
Msg-id 20100212102146.77a485a3@dawn.webthatworks.it
обсуждение исходный текст
Ответ на C function to create tsquery not working  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Список pgsql-general
On Thu, 11 Feb 2010 20:11:54 +0100
Ivan Sergio Borgonovo <mail@webthatworks.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


В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Make sure there is no two column with same value - What is the best practice?
Следующее
От: "Davor J."
Дата:
Сообщение: Re: Function that creates a custom (temporary) table AND returns a pointer to it = impossible in pg?