Re: Simplifying Text Search - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Simplifying Text Search
Date
Msg-id 16342.1195077853@sss.pgh.pa.us
Whole thread Raw
In response to Re: Simplifying Text Search  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> [ replace LIKE with this: ]

> 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; $$;

Cute trick, but as-is this will not make anything go any faster, because
it doesn't expose any opportunities for indexing the @@ operation.
I think what you'd really need is something like

$$ SELECT to_tsvector('english', $1) @@ likepattern_to_tsquery($2) AND $1 #~~# $2; $$;

which will win if there is an expression index on to_tsvector('english',
<textcolumn>).  (You can substitute your preferred configuration of
course, but you don't get to rely on default_text_search_config, because
that would render the expression non-immutable and thus non-indexable.)

This points up the same old notational problem that there is no good
place in the operator notation to mention which text search
configuration you want to use.  Simon's suggestion of a three-parameter
function at least addresses that issue.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: psql -f doesn't complain about directories
Next
From: Tom Lane
Date:
Subject: Re: Simplifying Text Search