Alex Rivera | Logout

Postgres full-text search with synonyms

Asked 2012-08-07T19:47:34.207
8

I have a database of restaurants which I do a full-text search on. The code looks something like this:

SELECT * FROM restaurant WHERE restaurant.search_vector @@ plainto_tsquery(:terms);

And search_vector is defined like this:

alter table restaurant add column search_vector tsvector;
create index restaurant_search_index on restaurant using gin(search_vector);
create trigger restaurant_search_update before update or insert on restaurant
    for each row execute procedure
    tsvector_update_trigger('search_vector',
    'pg_catalog.english','title');

Now, a notable problem with this search is the word barbecue. It can be spelled many different ways: barbecue, barbeque, BBQ, B.B.Q., B-B-Q, etc. When somebody searches any of these, I need to search restaurants for all of these terms.

From what I've read online, it seems I need to modify the dictionary (That would be pg_catalog.english, right?), but I'm not sure how to go about this.

Edit
Report

1 Answer

1

When I drumbled over a similiar problem I came across the option for Query Rewrites, see http://www.postgresql.org/docs/8.3/static/textsearch-features.html forexample, section 12.4.2.1

This is an easier approach then tackling the dictionary as it allows instantly extending your rewrite rules by just inserting new rules in your rewrite table.

answered 2012-08-07T20:00:56.947

Your Answer