首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不带位置偏移的Concat postgresql tsvectos

不带位置偏移的Concat postgresql tsvectos
EN

Stack Overflow用户
提问于 2021-09-27 13:25:06
回答 1查看 33关注 0票数 0

基于https://www.postgresql.org/docs/13/textsearch-features.html

代码语言:javascript
复制
tsvector || tsvector
The tsvector concatenation operator returns a vector which combines the lexemes and positional information of the two vectors given as arguments. Positions and weight labels are retained during the concatenation. Positions appearing in the right-hand vector are offset by the largest position mentioned in the left-hand vector, so that the result is nearly equivalent to the result of performing to_tsvector on the concatenation of the two original document strings. (The equivalence is not exact, because any stop-words removed from the end of the left-hand argument will not affect the result, whereas they would have affected the positions of the lexemes in the right-hand argument if textual concatenation were used.)

One advantage of using concatenation in the vector form, rather than concatenating text before applying to_tsvector, is that you can use different configurations to parse different sections of the document. Also, because the setweight function marks all lexemes of the given vector the same way, it is necessary to parse the text and do setweight before concatenating if you want to label different parts of the document with different weights.

因此,该查询

代码语言:javascript
复制
select 'a:1 b:2'::tsvector || 'a:1 c:2 b:3'::tsvector;

将导致'a':1,3 'b':2,5 'c':4

请告诉我,有没有一种方法可以在保留原始位置的同时合并几个tsvector(类似于下面的内容):

代码语言:javascript
复制
select concat_with_preserving('a:1 b:2'::tsvector, 'a:1 c:2 b:3'::tsvector);

所以它等于'a':1 'b':2,3 'c':2,例如相同的位置去重,不同的位置只是合并(无偏移量)。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-09-27 18:07:29

然后转换为文本,然后用空格将它们连接起来,然后再将它们转换回来。

代码语言:javascript
复制
(a::text || ' ' || b::text)::tsvector
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69347455

复制
相关文章

相似问题

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