Postgresql全文搜索部分文字 [英] Postgresql full text search part of words

查看:104
本文介绍了Postgresql全文搜索部分文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Postresql是否能够进行全文搜索,基于'half'这个单词?
例如我试图寻找tree,但我告诉postgres搜索tr

我无法找到这样一个能够做到这一点的解决方案。



目前我使用

  select * from test,to_tsquery('tree')as q where vectors @@ q; 

但我想这样做:

  select * from test,to_tsquery('tr%')as q where vectors @@ q; 


解决方案

听起来像只是想通配符匹配。 >


  • 如前所述,一个选项是 trigrams 。我的(非常)有限的经验是,它在我喜欢的大型桌子上速度太慢(有些情况比LIKE慢)。正如我所说,我对trigrams的使用经验有限,所以我可能会错误地使用它。

  • 第二个选项是你可以使用 wildspeed 模块: http:// www。 sai.msu.su/~megera/wiki/wildspeed
    (您将不得不构建和安装此tho)。




第二个选项也适用于后缀/中间匹配。这可能是也可能不会超过你正在寻找的。

有几个警告(如索引的大小),请仔细阅读该页面。

Is postresql capable of doing a full text search, based on 'half' a word? For example I'm trying to seach for "tree", but I tell postgres to search for "tr".

I can't find such a solution that is capable of doing this.

Currently I'm using

 select * from test, to_tsquery('tree') as q where vectors @@ q ;

But I'd like to do something like this:

 select * from test, to_tsquery('tr%') as q where vectors @@ q ;

解决方案

Sounds like you simply want wildcard matching.

  • One option, as previously mentioned is trigrams. My (very) limited experience with it was that it was too slow on massive tables for my liking (some cases slower than a LIKE). As I said, my experience with trigrams is limited, so I might have just been using it wrong.

  • A second option you could use is the wildspeed module: http://www.sai.msu.su/~megera/wiki/wildspeed (you'll have to build & install this tho).

The 2nd option will work for suffix/middle matching as well. Which may or may not be more than you're looking for.

There are a couple of caveats (like size of the index), so read through that page thoroughly.

这篇关于Postgresql全文搜索部分文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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