在我的表格中,我需要从文本数组中创建一个
tsvector
,然后相应地 setweight
。但似乎不起作用:
select
setweight(to_tsvector('simple', 'test vector of multiple values'), 'A') as "simple",
setweight(to_tsvector('simple', array_to_string(array['test', 'vector', 'of', 'multiple', 'values'], ' ')), 'A') as "string array",
setweight(array_to_tsvector('{test, vector, of, multiple, values}'::text[]), 'A') as "text array",
setweight(array_to_tsvector(array['test', 'vector', 'of', 'multiple', 'values']), 'A') as "array"
这给了我:
简单 | 字符串数组 | 文本数组 | 数组 |
---|---|---|---|
'多个':4A'的':3A'测试':1A'值':5A'向量':2A | '多个':4A'的':3A'测试':1A'值':5A'向量':2A | “多个”“测试”“值”“向量” | “多个”“测试”“值”“向量” |
请注意最后两列中没有权重。 试图用谷歌搜索一些相关内容,但我发现的唯一的东西是这个主题没有有意义的评论。
同样,我不需要索引或搜索数组,并且
array_to_string
解决方法对我来说似乎也有点难看(就像上述主题的作者一样)。
我错过了什么
array_to_tsvector
?或者也许setweight
?
来自文档:
请注意,权重标签适用于位置,而不是词位。如果输入向量已被去除位置,则 setweight 不会执行任何操作。
我不知道最好的解决方法是什么,因为我不知道你在做什么。如果你不对权重做任何事情,那么设置权重就没有意义。