加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – Postgres引发匹配

发布时间:2020-12-13 16:32:34 所属栏目:百科 来源:网络整理
导读:查询 SELECT to_tsvector(‘entertainment’)@@ to_tsquery(‘recreatio:*’); 即使“recreati”是“娱乐”的前缀,也返回false.这似乎是因为“娱乐”被储存为它的干,“重新”.例如,如果我们通过运行故意破坏干扰算法 SELECT to_tsvector(‘entertainment1’
查询

SELECT to_tsvector(‘entertainment’)@@ to_tsquery(‘recreatio:*’);

即使“recreati”是“娱乐”的前缀,也返回false.这似乎是因为“娱乐”被储存为它的干,“重新”.例如,如果我们通过运行故意破坏干扰算法

SELECT to_tsvector(‘entertainment1’)@@ to_tsquery(‘recreatio:*’);

查询返回true.

有没有办法使第一个查询匹配?

不确定这个答案是否有用,因为问题的年龄,但是:

关于遏制

看来你是对的:

select ts_lexize('english_stem','recreation');

输出

ts_lexize
-----------
 {recreat}
(1 row)

和documentation说

Also,* can be attached to a lexeme to specify prefix matching:

SELECT to_tsquery('supern:*A & star:A*B');

Such a lexeme will match any word in a tsvector that begins with the given string.

所以似乎没有办法使原始查询匹配.

基于部分匹配的解决方案

人们可能会回头寻找茎和查询的部分匹配,例如.使用pg_trgm扩展名

SELECT (to_tsvector('recreation creation') @@ to_tsquery('recreatio:*')) or 
  'recreatio:*' % any (
    select trim(both '''' from regexp_split_to_table(strip(to_tsvector('recreation creation'))::text,' '))
  );

(可能会以更优雅的方式形成茎的阵列.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读