Postgresql全文搜索部分文字

编程入门 行业动态 更新时间:2024-10-25 04:24:35
本文介绍了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: 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全文搜索部分文字

本文发布于:2023-10-25 18:27:12,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文字   全文   Postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!