gpt4 book ai didi

Why in PostgreSQL setweight doesn't set weight for array_to_tsvector?(为什么在PostgreSQL中,setweight没有为arrayto_tsVECTOR设置权重?)

转载 作者:bug小助手 更新时间:2023-10-28 10:28:13 26 4
gpt4 key购买 nike



In my table I need to create a tsvector out of an array of text and then setweight it accordingly. But it doesn't seem to work:

在我的表中,我需要从一个文本数组中创建一个tsvector,然后相应地对它进行排序。但它似乎不起作用:


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"

This gives me:

这给了我:




















simple string array text array array
'multiple':4A 'of':3A 'test':1A 'values':5A 'vector':2A 'multiple':4A 'of':3A 'test':1A 'values':5A 'vector':2A 'multiple' 'of' 'test' 'values' 'vector' 'multiple' 'of' 'test' 'values' 'vector'


Notice the absence of weights in last 2 columns.
Tried to google something about it but the only thing I found was this topic without meaningful comments.

请注意,最后两列中没有权重。我试着在谷歌上搜索一些关于它的东西,但我唯一找到的就是这个话题,没有任何有意义的评论。


Again, I don't need to index or search an array and array_to_string workaround seems a bit ugly to me too (just like the author of the mentioned topic).

同样,我不需要索引或搜索数组,数组到字符串的解决方法在我看来也有点难看(就像前面提到的主题的作者一样)。


What am I missing about array_to_tsvector? Or setweight perhaps?

关于ARRAY_TO_TSVECTOR,我遗漏了什么?或者是赛特威特?


更多回答
优秀答案推荐

From the docs:

从文档中:



Note that weight labels apply to positions, not lexemes. If the input vector has been stripped of positions then setweight does nothing.



I don't know what the best work-around is, as I don't know what you are doing. Setting weights is pointless if you don't do anything with them.

我不知道最好的变通办法是什么,因为我不知道你在做什么。如果不对权重执行任何操作,则设置权重是毫无意义的。


更多回答

Don't know how I missed that part. Thanks! I guess this is how it had to be done: $$'test':1A 'vector':2A 'of':3A 'multiple':4A 'values':5A$$::tsvector. But looks like using array_to_string is much better in the end.

不知道我怎么会错过了这一部分。谢谢!我想这是必须这样做的:$$‘test’:1a‘VECTOR’:2a‘of’:3A‘Multiple’:4A‘Values’:5A$$::tsVECTOR。但最终看起来使用arraytostring要好得多。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com