Re: Simplifying Text Search - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Simplifying Text Search
Date
Msg-id 200711141324.lAEDOhG22100@momjian.us
Whole thread Raw
In response to Re: Simplifying Text Search  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Simon Riggs wrote:
> 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

One advantage to this syntax is that it allows the specification of the
configuration name, which needs a function call to be done with the @@
operator.  

However, to access a tsvector column we would need to add another
function that takes a tsvector value.  However, the config specification
would apply only to the text column, not the pre-computed tsvector, so
that might be confusing.  I think this method could use a function index
but it wouldn't be very clear from the syntax.

The problem I always kept having in clarifying the syntax is that I
could never find anything that covered all common use cases.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://postgres.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


pgsql-hackers by date:

Previous
From: "Zeugswetter Andreas ADI SD"
Date:
Subject: Re: How to keep a table in memory?
Next
From: Tom Lane
Date:
Subject: Re: Spinlock backoff algorithm