Search Postgresql Archives

tsearch2: setting weights on tsquery plainto_tsquery with | or and weight

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 21 Oct 2008 13:40:33 -0400
Tom Lane <tgl@xxxxxxxxxxxxx> wrote:

> Ivan Sergio Borgonovo <mail@xxxxxxxxxxxxxxx> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux