Postgres使用同义词进行全文搜索 [英] Postgres full-text search with synonyms

查看:237
本文介绍了Postgres使用同义词进行全文搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个餐馆数据库,我在那里进行全文搜索。代码看起来像这样:

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);

search_vector 定义如下:

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.

从我在线阅读的内容看来,我似乎需要修改字典(这将是 pg_catalog.english ,对吗?),但我不确定如何去做这件事。

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.

推荐答案

听起来像你想要做的是添加同义词字典在你的英语之前。尽管这只能用于单个单词,所以您可能在B.B.Q中遇到问题。如果它被解析为三个独立的标记。

Sounds like what you want to do is add a synonym dictionary in front of your english one. This will only work on single words though, so you might have problems with B.B.Q. if it gets parsed as three separate tokens.

postgresql.org文档中的同义词词典

这篇关于Postgres使用同义词进行全文搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆