首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tsvector向量中的词位

tsvector向量中的词位
EN

Stack Overflow用户
提问于 2019-05-20 12:35:07
回答 1查看 314关注 0票数 1

我有以下几行案文:

"Blue pill"; "Red pill"; "Blue shift"; "Red eye"

我想选择行,其中Red是第一个单词,或者Pill是第二个单词。假设情况下,可以使用tsquerytsvector来完成,因为tsvector的输出也包含每个词的位置。然而,我没有发现任何函数允许访问向量的数字。是否有适当的方法来选择行,在定义的位置匹配ts_query

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-20 14:06:46

使用to实现这一点是可能的

代码语言:javascript
复制
with data as (
  select * from (
  VALUES (1, 'Blue pill'),
         (2, 'Red pill'),
         (3, 'Blue shift'),
         (4, 'Red eye')
  ) v(id, t)
)
select id, lexeme, positions
FROM data
CROSS JOIN unnest(to_tsvector(t)) u(lexeme, positions, weights)
WHERE (lexeme = 'red' and positions @> '{1}')
OR (lexeme = 'pill' and positions @> '{2}');
 id | lexeme | positions
----+--------+-----------
  1 | pill   | {2}
  2 | pill   | {2}
  2 | red    | {1}
  4 | red    | {1}
(4 rows)

不过,我认为使用正则表达式可能更容易做到这一点。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56221163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档