mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Full Text Search support for json and jsonb
The new functions are ts_headline() and to_tsvector. Dmitry Dolgov, edited and documented by me.
This commit is contained in:
@ -551,3 +551,29 @@ select json_strip_nulls('[1,{"a":1,"b":null,"c":2},3]');
|
||||
|
||||
-- an empty object is not null and should not be stripped
|
||||
select json_strip_nulls('{"a": {"b": null, "c": null}, "d": {} }');
|
||||
|
||||
-- json to tsvector
|
||||
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::json);
|
||||
|
||||
-- json to tsvector with config
|
||||
select to_tsvector('simple', '{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::json);
|
||||
|
||||
-- json to tsvector with stop words
|
||||
select to_tsvector('{"a": "aaa in bbb ddd ccc", "b": ["the eee fff ggg"], "c": {"d": "hhh. iii"}}'::json);
|
||||
|
||||
-- ts_vector corner cases
|
||||
select to_tsvector('""'::json);
|
||||
select to_tsvector('{}'::json);
|
||||
select to_tsvector('[]'::json);
|
||||
select to_tsvector('null'::json);
|
||||
|
||||
-- ts_headline for json
|
||||
select ts_headline('{"a": "aaa bbb", "b": {"c": "ccc ddd fff", "c1": "ccc1 ddd1"}, "d": ["ggg hhh", "iii jjj"]}'::json, tsquery('bbb & ddd & hhh'));
|
||||
select ts_headline('english', '{"a": "aaa bbb", "b": {"c": "ccc ddd fff"}, "d": ["ggg hhh", "iii jjj"]}'::json, tsquery('bbb & ddd & hhh'));
|
||||
select ts_headline('{"a": "aaa bbb", "b": {"c": "ccc ddd fff", "c1": "ccc1 ddd1"}, "d": ["ggg hhh", "iii jjj"]}'::json, tsquery('bbb & ddd & hhh'), 'StartSel = <, StopSel = >');
|
||||
select ts_headline('english', '{"a": "aaa bbb", "b": {"c": "ccc ddd fff", "c1": "ccc1 ddd1"}, "d": ["ggg hhh", "iii jjj"]}'::json, tsquery('bbb & ddd & hhh'), 'StartSel = <, StopSel = >');
|
||||
|
||||
-- corner cases for ts_headline with json
|
||||
select ts_headline('null'::json, tsquery('aaa & bbb'));
|
||||
select ts_headline('{}'::json, tsquery('aaa & bbb'));
|
||||
select ts_headline('[]'::json, tsquery('aaa & bbb'));
|
||||
|
Reference in New Issue
Block a user