Re: tsearch2: more than one index per table?

Lists: pgsql-general
From: "Rick Schumeyer" <rschumeyer(at)ieee(dot)org>
To: "'PgSql General'" <pgsql-general(at)postgresql(dot)org>
Subject: tsearch2: more than one index per table?
Date: 2005-11-23 04:45:05
Message-ID: 017601c5efe8$afeb4610$0300a8c0@dell8200
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Is there something in tsearch2 that prevents more than one index per table?

I would like an index on field A, and a separate index on field B.

The index builds fine for A, but gives an error for B. The error text is

ERROR: could not find tsearch config by locale

The code below is taken almost verbatim from the tsearch2 documentation.

Any help is appreciated!

================================================================

\i /home/rick/ftp/postgresql-8.1.0/contrib/tsearch2/tsearch2.sql

CREATE TABLE t (a varchar(20), b varchar(20));

INSERT INTO t (a,b) VALUES ('hello world','quick brown fox');

--

-- A

--

ALTER TABLE t ADD COLUMN idxA tsvector;

UPDATE t SET idxA=to_tsvector('default', a);

VACUUM FULL ANALYZE;

CREATE INDEX idxA_idx ON t USING gist(idxA);

VACUUM FULL ANALYZE;

CREATE TRIGGER ts_A_Update BEFORE UPDATE OR INSERT ON t

FOR EACH ROW EXECUTE PROCEDURE tsearch2(idxA, a);

--

-- B

--

ALTER TABLE t ADD COLUMN idxB tsvector;

--

-- The next line gives: ERROR: could not find tsearch config by locale

--

UPDATE t SET idxB=to_tsvector('default', b);

VACUUM FULL ANALYZE;

CREATE INDEX idxB_idx ON t USING gist(idxB);

VACUUM FULL ANALYZE;

CREATE TRIGGER ts_B_Update BEFORE UPDATE OR INSERT ON t

FOR EACH ROW EXECUTE PROCEDURE tsearch2(idxB, b);


From: "Andrew J(dot) Kopciuch" <akopciuch(at)bddf(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 05:08:28
Message-ID: 200511222208.28678.akopciuch@bddf.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tuesday 22 November 2005 21:45, Rick Schumeyer wrote:
> Is there something in tsearch2 that prevents more than one index per table?
>
> I would like an index on field A, and a separate index on field B.
>
> The index builds fine for A, but gives an error for B. The error text is
>
>
>
> ERROR: could not find tsearch config by locale
>
>

This is not a problem with the index creation ... your tsearch2 installation
is not configured for the locale your server is running.

http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html

See the section "TSEARCH2 CONFIGURATION". It explains, and has examples on
how to set this up.

cheers,

Andy


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Rick Schumeyer <rschumeyer(at)ieee(dot)org>
Cc: 'PgSql General' <pgsql-general(at)postgresql(dot)org>
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 07:36:45
Message-ID: 43841C0D.1030407@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

> ERROR: could not find tsearch config by locale
> UPDATE t SET idxA=to_tsvector('default', a);
>

Is it working
select to_tsvector('foo bar')?

I suppose, no. In that case tsearch can't find configuration for current
database locale, update pg_ts_cfg.locale in wished row to correct value.

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Rick Schumeyer <rschumeyer(at)ieee(dot)org>, "'PgSql General'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 07:57:26
Message-ID: Pine.GSO.4.63.0511231055400.29329@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, 23 Nov 2005, Teodor Sigaev wrote:

>> ERROR: could not find tsearch config by locale
>> UPDATE t SET idxA=to_tsvector('default', a);
>>
>
> Is it working
> select to_tsvector('foo bar')?
>
> I suppose, no. In that case tsearch can't find configuration for current
> database locale, update pg_ts_cfg.locale in wished row to correct value.

Actually, it's described in tsearch2 introduction.
Make sure pg_ts_cfg.locale matched server's locale (see 'show all')

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: "Andrew J(dot) Kopciuch" <akopciuch(at)bddf(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 10:31:26
Message-ID: Pine.GSO.4.63.0511231330240.29329@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tue, 22 Nov 2005, Andrew J. Kopciuch wrote:

> This is not a problem with the index creation ... your tsearch2 installation
> is not configured for the locale your server is running.
>
> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html
>
> See the section "TSEARCH2 CONFIGURATION". It explains, and has examples on
> how to set this up.

I added paragraph about this problem, check my notes
http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_Notes

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83


From: "Rick Schumeyer" <rschumeyer(at)ieee(dot)org>
To: <akopciuch(at)bddf(dot)ca>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 13:55:21
Message-ID: 019301c5f035$8da34e70$0300a8c0@dell8200
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I apologize if I'm being dense, but I'm not completely following the
explanation. It is true that my pg_ts_cfg.locale is set to en_US.UTF-8.

It was my understanding that specifying "default" as in

UPDATE t SET idxB=to_tsvector('default', b);

should give tsearch enough information.

It is not clear to me why the first time works, but not the second time
with almost identical statements.

I thought that I only had to follow the procedure in the docs if I want
to do the following:

UPDATE t SET idxB=to_tsvector(b); -- no 'default'

Perhaps I am wrong about this?

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Andrew J. Kopciuch
> Sent: Wednesday, November 23, 2005 12:08 AM
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] tsearch2: more than one index per table?
>
> On Tuesday 22 November 2005 21:45, Rick Schumeyer wrote:
> > Is there something in tsearch2 that prevents more than one index per
> table?
> >
> > I would like an index on field A, and a separate index on field B.
> >
> > The index builds fine for A, but gives an error for B. The error text
> is
> >
> >
> >
> > ERROR: could not find tsearch config by locale
> >
> >
>
>
> This is not a problem with the index creation ... your tsearch2
> installation
> is not configured for the locale your server is running.
>
> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-
> intro.html
>
> See the section "TSEARCH2 CONFIGURATION". It explains, and has examples
> on
> how to set this up.


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Rick Schumeyer <rschumeyer(at)ieee(dot)org>
Cc: akopciuch(at)bddf(dot)ca, pgsql-general(at)postgresql(dot)org
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 14:26:06
Message-ID: Pine.GSO.4.63.0511231719520.29329@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, 23 Nov 2005, Rick Schumeyer wrote:

> I apologize if I'm being dense, but I'm not completely following the
> explanation. It is true that my pg_ts_cfg.locale is set to en_US.UTF-8.
>
> It was my understanding that specifying "default" as in
>
> UPDATE t SET idxB=to_tsvector('default', b);
>
> should give tsearch enough information.
>
> It is not clear to me why the first time works, but not the second time
> with almost identical statements.
>
> I thought that I only had to follow the procedure in the docs if I want
> to do the following:
>
> UPDATE t SET idxB=to_tsvector(b); -- no 'default'
>
> Perhaps I am wrong about this?

nothing wrong except trigger you defined 'BEFORE UPDATE OR INSERT' fired
and it has no knowledge which configuration to use.
You may put trigger statement after update, but you'll get the same
error when inserting something to table.

Don't resist and configure tsearch2 to match server's locale.
It's most painless way.

>
>> -----Original Message-----
>> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
>> owner(at)postgresql(dot)org] On Behalf Of Andrew J. Kopciuch
>> Sent: Wednesday, November 23, 2005 12:08 AM
>> To: pgsql-general(at)postgresql(dot)org
>> Subject: Re: [GENERAL] tsearch2: more than one index per table?
>>
>> On Tuesday 22 November 2005 21:45, Rick Schumeyer wrote:
>>> Is there something in tsearch2 that prevents more than one index per
>> table?
>>>
>>> I would like an index on field A, and a separate index on field B.
>>>
>>> The index builds fine for A, but gives an error for B. The error text
>> is
>>>
>>>
>>>
>>> ERROR: could not find tsearch config by locale
>>>
>>>
>>
>>
>> This is not a problem with the index creation ... your tsearch2
>> installation
>> is not configured for the locale your server is running.
>>
>> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-
>> intro.html
>>
>> See the section "TSEARCH2 CONFIGURATION". It explains, and has examples
>> on
>> how to set this up.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83


From: "Andrew J(dot) Kopciuch" <akopciuch(at)bddf(dot)ca>
To: "Rick Schumeyer" <rschumeyer(at)ieee(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: tsearch2: more than one index per table?
Date: 2005-11-23 15:21:38
Message-ID: 200511230821.39096.akopciuch@bddf.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wednesday 23 November 2005 06:55, Rick Schumeyer wrote:
> I apologize if I'm being dense, but I'm not completely following the
> explanation. It is true that my pg_ts_cfg.locale is set to en_US.UTF-8.
>
> It was my understanding that specifying "default" as in
>

That takes the locale that is specified in the tsearch2 configuration called
"default";

take a look at this :

ftstest=# select * from pg_ts_cfg;
ts_name | prs_name | locale
-----------------+----------+--------------
default | default | C
default_russian | default | ru_RU.KOI8-R
simple | default |
custom | default |

If you don't have a record in that table that matches the server encoding
(en_US.UTF-8), you need to create a new configuration to use that locale.
That's all describe in the link I sent before.

If you have a configuration you always want to use you can just switch to that
configuration.

If you do something like this :

ftstest=# select set_curcfg('simple');
set_curcfg
------------

(1 row)

ftstest=# select to_tsvector('simple', 'a simple test');
to_tsvector
---------------------------
'a':1 'test':3 'simple':2
(1 row)

ftstest=# select to_tsvector('a simple test');
to_tsvector
---------------------------
'a':1 'test':3 'simple':2
(1 row)

ftstest=# select to_tsvector('default', 'a simple test');
to_tsvector
--------------------
'test':3 'simpl':2
(1 row)

The second example does not specify a configuration, but because you set in
the set_curcfg statement it knows to use the "simple" configuration.

> UPDATE t SET idxB=to_tsvector('default', b);
>

This forces a configuration called "default"

> UPDATE t SET idxB=to_tsvector(b); -- no 'default'
>

This doesn't tell it which configuration to use, so it tries to find one that
matches your locale (en_US.UTF-8). There probably isn't one in pg_ts_cfg, so
it gives the error.

hth,

Andy