Re: Simplifying Text Search

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Simplifying Text Search
Date: 2007-11-14 06:25:12
Message-ID: 1195021512.4378.73.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 2007-11-13 at 08:58 +0100, Pavel Stehule wrote:
> On 13/11/2007, Simon Riggs <simon(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2007-11-14 07:39:06 Re: How to keep a table in memory?
Previous Message Tom Lane 2007-11-14 05:37:26 Re: [HACKERS] plperl and regexps with accented characters - incompatible?