Re: tokenize string for tsearch?

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: tokenize string for tsearch?
Date: 2007-05-08 04:40:22
Message-ID: Pine.LNX.4.64.0705080836150.12152@sn.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 7 May 2007, Ottavio Campana wrote:

> Hi, I'm trying to use tsearch2 for the first time and I'm having a
> problem setting up a query
>
> If I execute
>
> SELECT * from test_table where ts_desc @@ to_tsquery ('hello&world');
>
> it works, but I'm having the problem that the string used for the query
> is not 'hello&world' but 'hello world', Moreover, it can have an
> arbitrary number of spaces between the words, so I cannot just
> substitute the spaces with &, because 'hello&&world' gives error.
>
> What is the safest way transform a string into a list of works "anded"
> together?

Don't worry, see how default parser works:

postgres=# select parse('default','hello world');
parse
--------------
(1,hello)
(12," ")
(1,world)

btw, you can use plainto_tsquery for AND query

=# select plainto_tsquery('hello world');
plainto_tsquery
-------------------
'hello' & 'world'
(1 row)

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paul Lambert 2007-05-08 04:42:45 Re: Vacuuming
Previous Message Tom Lane 2007-05-08 04:20:19 Re: Vacuuming