Acts_as_tsearch adjustments needed for PostgreSQL 8.3rc2

Just a quick note: acts_as_tsearch needs some guidance to work with PostgreSQL 8.3 due to changes in tsearch2 integration.

I’m pretty close to tossing out acts_as_tsearch and rolling my own (trigger-based) tsearch2 plugin, but for now I’m just sticking with it and checking out the PostgreSQL 8.3 release candidate.

I was able to build 8.3rc2 on Mac OS X 10.5.1 from the tarball sources with the instructions in the INSTALL document, no hitches whatsoever. Because I have 8.2 installed via MacPorts, there were no file conflicts (different install directories, data directories, etc.), so all I had to due was shut down the 8.2 server and start the 8.3rc2 server and it was ready to go.

Unfortunately, acts_as_tsearch didn’t work properly the way I had used with with 8.2. The issue appears to be that the tsearch2 locale called ‘default’ is gone, which is what acts_as_tsearch uses if you don’t specify something else. The default locale value is now located in postgresql.conf. Using that value as an explicit locale in the acts_as_tsearch declaration in my model class solved the problem. The code change looks like this:

OLD:
acts_as_tsearch :fields => ["subject","body"]

NEW:
acts_as_tsearch :vector => {:fields => ["subject","body"], :locale => 'pg_catalog.english'}

Like I said, due to the fact that acts_as_tsearch is designed to hide the complexity of tsearch2, it is not well suited to my somewhat complex requirements. So, I’m ditching it in favor of custom code, which I hope to plugin-ize and release some time later. So, this change is necessary but might not be sufficient for your own project. But I hope it helps you get started on upgrading successfully.

1 thought on “Acts_as_tsearch adjustments needed for PostgreSQL 8.3rc2”

  1. Thanks for the description, this helped me to save a lot of time. But I think you have a little error in the new code, it should be ‘:vectors’ not ‘vector’.

Leave a Reply

Your email address will not be published. Required fields are marked *