On Tue, 2007-11-13 at 08:58 +0100, Pavel Stehule wrote:
> On 13/11/2007, Simon Riggs <[EMAIL PROTECTED]> wrote:
> > I'm thinking we can have an inlinable function
> >
> > contains(text, text) returns int
> >
> > Return values limited to just 0 or 1 or NULL, as with SQL/MM.
> > It's close to SQL/MM, but not exact.
> >
> > contains(sourceText, searchText) is a macro for
> >
> > case to_tsvector(default_text_search_config, sourceText) @@
> > to_tsquery(default_text_search_config, searchText)
> > when true then 1
> > when false then 0
> > else null
> > end

Better idea:

in-linable function called

create function
contains(sourceText text, searchText text, config text) returns boolean
as $$
to_tsvector(config, sourceText) @@ to_tsquery(config, searchText);
$$ language sql;

so that 

SELECT title
FROM pgweb
WHERE contains(body, 'a & b', 'english')

is an indexable, easily readable way of using full text search.

allowing 

SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat');
 ?column? 
----------
 t

to become

SELECT contains('fat cats ate fat rats', 'fat & rat', 'english');
 ?column? 
----------
 t

Proposed changes:
1. Add function contains()
2. Alter docs to show use of contains()

All other @@ features still the same

-- 
  Simon Riggs
  2ndQuadrant  http://www.2ndQuadrant.com


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to