From: | Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | tsearch2: setting weights on tsquery plainto_tsquery with | or and weight |
Date: | 2008-10-21 18:37:26 |
Message-ID: | 20081021203726.15c87109@dawn.webthatworks.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 21 Oct 2008 13:40:33 -0400
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> writes:
> > I missed it. Thanks. Nearly perfect. Now I've to understand what
> > a {} is.
> > An array with a null element? an empty array? an array
> > containing ''?
>
> Hmm ... it appears that ts_lexize is returning a one-dimensional
> array of no elements, whereas '{}'::text[] returns a
> zero-dimensional array; as does array[]::text[] so you can't
> easily get around it :-(
Maybe in 8.4. I'm already thankful this toy is making such wonders.
> We probably ought to clean this up...
>
> In the meantime it looks like you could check for
> "array_upper(lexemes,1) > 0".
My version as posted before was the >=1 variant.
This is what I was trying to obtain a weighted version of
plainto_tsquery with parametrised operator:
I think I'm wasting some cpu cycles when ts_debug try to fill the
lexemes array that I'm not using.
So maybe there should be more finer access to the functions to help
build up tsquery.
The ts_parse is missing the information about what tokens should be
discarded.
create or replace function setweight(configuration regconfig,
queryin text, weight char, op char ,out query tsquery) as
$$
declare
tsdebug record;
querystring text;
begin
querystring:='';
for tsdebug in select token from
ts_debug(configuration, queryin)
where array_upper(lexemes,1)>0 loop
querystring:=querystring ||
coalesce(tsdebug.token ||
coalesce(':' || weight, '') ||
' ', '');
end loop;
querystring:=regexp_replace(querystring, ' (.)',
op || '\\1', 'g');
query:=to_tsquery(configuration, querystring);
return;
end;
$$ language plpgsql immutable;
--
Ivan Sergio Borgonovo
http://www.webthatworks.it
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2008-10-21 20:57:52 | Re: statement_timeout by host? |
Previous Message | Glen Brown | 2008-10-21 17:54:50 | Slow to delete TOAST table data |