Skip to main content.

Saturday, November 05, 2005

Long time no blog. Now, back to the joys of tinkering with Wikipgedia.
I got stuck last week with a missing table that Robert Treat (one of the Wikipgedia developers) added shortly afterwards.

So I updated my source to today's CVS version and installed again. (If it's not in place already: create a database beforehand containing a schema called mediawiki. Add TSearch2 support to the database. See my last post for details.)

When filling in the info for the MediaWiki installer, remember to enter the name of the database, not the name of the schema, where prompted for "database name".

Then everything is set up and running.

Trying to edit a page...
A database error has occurred
Query: INSERT INTO searchindex (si_page,si_title,si_text) VALUES ( 1, to_tsvector('main page'),to_tsvector(' first try '))
Function: SearchTsearch2:update
Error: 1
ERROR: could not find tsearch config by locale


This is because by initializing the database server, the PostgreSQL locale is set automatically to the system's locale, which is de_DE.UTF-8 on my system. Wikipgedia is using to_tsvector() with only one parameter, assuming the TSearch2 locale configured properly in accordance to the system's locale. Which it isn't.

Out of the box, TSearch2 only knows the Posix C and the russian locale.

Now there are two possibilities: Forcing Wikipgedia to use the default C locale or configuring TSearch2 with the german locale.

Forcing Wikipgedia to use the C locale
In includes/SearchTsearch2.php change all occurrences of to_tsvector() to use the 2-parameter version of to_tsvector():

112c113
< " VALUES ( $id, to_tsvector('".
---
> " VALUES ( $id, to_tsvector('default','".
114c115
< "'),to_tsvector('".
---
> "'),to_tsvector('default','".
122c123
< $sql = "UPDATE $searchindex SET si_title=to_tsvector('" .
---
> $sql = "UPDATE $searchindex SET si_title=to_tsvector('default','" .


The best solution would be to determine in the beginning if TSearch2 is supporting the current locale and if not, use to_tsvector() with the default one.


Configuring TSearch2 with the german locale:
The TSearch2 documentation chapter on configuration provides details on using TSearch2 with other locales.

Check for the locale as set at initialization:
pg_controldata /usr/local/pgsql/data | grep LC
In my case:
LC_COLLATE: de_DE.UTF-8
LC_CTYPE: de_DE.UTF-8

Check for available locales in TSearch2:
select oid,* from pg_ts_cfg;
Check for the locale currently used by TSearch2:
select show_curcfg();
Insert a new locale:
INSERT INTO pg_ts_cfg (ts_name, prs_name, locale) VALUES ('default_german', 'default', 'de_DE.UTF-8');

This only declares that there is a configuration for this locale. (If you stop here, Wikipgedia/PostgreSQL will output "No parser with id 26810", the ID being the OID of the record I entered for my new locale).

There is a special Howto dedicated to configuring TSearch2 with the german locale.

As I am not going to use Wikipgedia with German content at the moment, I will leave this for later and just go on working with the patch discussed above.



Sunday, October 23, 2005

Wikipgedia is a MediaWiki with PostgreSQL backend. It is currently in v.0.0.1.
I installed the CVS version of today.

This is a Mini-HowTO.

PostgreSQL
Install PostgreSQL (I used 8.0.4)

flex
If you do not have flex installed, install flex. It will be needed later on by TSearch2 which is needed by Wikipgedia. If there is no flex, the error reads "ERROR: `flex' is missing on your system."
If you installed flex after installing PostgreSQL, you will still get the abovementioned error.
This is because postgresql-8.0.4/contrib/tsearch2/wordparser/Makefile checks for
ifdef FLEX
which is defined in the included Makefile.global of PostgreSQL (*if* it was installed at the time of installing PostgreSQL! Otherwise it is left blank).
You have to add
FLEX = /usr/bin/flex
in $(top_builddir)/src/Makefile.global at the appropriate line.

PHP
Add PostgreSQL support to PHP by either compiling PHP --with-pgsql or installing the php4-pgsql package (SuSE). Restart Apache afterwards, otherwise Mediawiki will output only "PostgreSQL functions missing, have you compiled PHP with the --with-pgsql option?"

TSearch2
MediaWiki needs TSearch2 which is not installed by default. Go to the folder where you have extracted the source tarball and there to postgresql-8.0.4/contrib/tsearch2/. gmake and gmake install. (or gmake -C contrib/tsearch2 from source root).
See the TSearch2-Intro for additional hints and a how-to for adding TSearch2 support to a database:
psql -U testuser testdb < tsearch2.sql
If you get
permission denied for language c
you have to either grant the necessary permission to the testuser oder load the script as the superuser (postgres).

Last Steps
- Create database with any name, create schema "mediawiki" inside it
- Point your browser to the Mediawiki installer and follow the instructions.

All troubles I encountered were fixed by following the steps above (PHP with pgsql, apache restart, tsearch2 install, flex install, adding flex to makefile.global).
Afterwards Wikipgedia is up and running :-)

When trying to edit a page I got
A database error has occurred Query: DELETE FROM searchindex WHERE si_page=1 Function: SearchTsearch2:update Error: 1 ERROR: relation "searchindex" does not exist

I will fix that tomorrow... Stay tuned!