Re: Simplifying Text Search - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: Simplifying Text Search
Date
Msg-id 1195021512.4378.73.camel@ebony.site
Whole thread Raw
In response to Re: Simplifying Text Search  ("Pavel Stehule" <pavel.stehule@gmail.com>)
Responses Re: Simplifying Text Search  (Gregory Stark <stark@enterprisedb.com>)
Re: Simplifying Text Search  (Bruce Momjian <bruce@momjian.us>)
Re: Simplifying Text Search  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, 2007-11-13 at 08:58 +0100, Pavel Stehule wrote:
> On 13/11/2007, Simon Riggs <simon@2ndquadrant.com> 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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] plperl and regexps with accented characters - incompatible?
Next
From: Simon Riggs
Date:
Subject: Re: How to keep a table in memory?