Re: Simplifying Text Search

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Simplifying Text Search
Дата
Msg-id 200711142138.28254.peter_e@gmx.net
обсуждение исходный текст
Ответ на Re: Simplifying Text Search  (Peter Eisentraut <peter_e@gmx.net>)
Ответы Re: Simplifying Text Search  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Simplifying Text Search  ("Trevor Talbot" <quension@gmail.com>)
Список pgsql-hackers
I wrote:
> What we'd need is a way to convert a LIKE pattern into a tsquery
> ('%foo%bar%' => 'foo & bar').  Then you might even be able to sneak
> index-optimized text search into existing applications.  Might be worth a
> try.

Here is how this could work:

CREATE FUNCTION likepattern_to_tsquery(text) RETURNS tsquery   RETURNS NULL ON NULL INPUT IMMUTABLE   LANGUAGE SQL   AS
$$SELECT trim(replace($1, '%', ' & '), '& ')::tsquery; $$;
 


UPDATE pg_operator SET oprname = '#~~#' WHERE oprcode = 'textlike'::regproc;


CREATE FUNCTION textlike_ts(text, text) RETURNS boolean   RETURNS NULL ON NULL INPUT IMMUTABLE   LANGUAGE SQL   AS $$
SELECT$1 @@ likepattern_to_tsquery($2) AND $1 #~~# $2; $$;
 


CREATE OPERATOR ~~ (   PROCEDURE = textlike_ts,   LEFTARG = text,   RIGHTARG = text
);

Maybe something like this could be useful for people who cannot readily change 
their application code.  (Of course it is not meant to solve the issue of how 
to make the text-search functionality itself easier to access.)

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


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

Предыдущее
От: Zdenek Kotala
Дата:
Сообщение: Re: psql -f doesn't complain about directories
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: psql -f doesn't complain about directories