Postgres:文本搜索,结合了多个JSONB tsvector

时间:2018-08-02 21:16:48

标签: postgresql full-text-search jsonb

在Postgres 10中,您可以全文搜索With (select Count(distinct(follower_account_id) as followers From pw_social_relation) Select count(distinct(follower_account_id))/followers From pw_social_relation Where count(followee_account_id)>=3 数据结构:

Key: ga:productSku
Imported Data: ga:metric13
Overwrite hit data: Yes

请注意tsvector如何仅索引JSON对象(智能)的值

现在,我想合并多个JSONB字段中的SELECT to_tsvector('english', '{"key":"value1"}'::jsonb); >>> [tsvector] >>> 'value1':1 ... 我可以...

tsvector

请注意,因为我已经强制转换为JSONB,所以我会得到键和值。...

我想合并多个tsvector()对象的输出-如何做到这一点?

1 个答案:

答案 0 :(得分:2)

请注意,jsonb值可以为concatenated:

SELECT '{"key":"value1"}'::jsonb || '{"key2":"value2"}'::jsonb AS new_jsonb

              new_jsonb              
-------------------------------------
 {"key": "value1", "key2": "value2"}
(1 row) 

您无需将其转换为文本:

SELECT to_tsvector('{"key":"value1"}'::jsonb || '{"key2":"value2"}'::jsonb );

      to_tsvector      
-----------------------
 'value1':1 'value2':3
(1 row)