From 1c1791e00065f6986f9d44a78ce7c28b2d1322dd Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Sat, 7 Apr 2018 20:58:03 +0300 Subject: Add json(b)_to_tsvector function Jsonb has a complex nature so there isn't best-for-everything way to convert it to tsvector for full text search. Current to_tsvector(json(b)) suggests to convert only string values, but it's possible to index keys, numerics and even booleans value. To solve that json(b)_to_tsvector has a second required argument contained a list of desired types of json fields. Second argument is a jsonb scalar or array right now with possibility to add new options in a future. Bump catalog version Author: Dmitry Dolgov with some editorization by me Reviewed by: Teodor Sigaev Discussion: https://www.postgresql.org/message-id/CA+q6zcXJQbS1b4kJ_HeAOoOc=unfnOrUEL=KGgE32QKDww7d8g@mail.gmail.com --- doc/src/sgml/func.sgml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index a86d3f40f17..3dbfa1dec34 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -9727,6 +9727,26 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple to_tsvector('english', '{"a": "The Fat Rats"}'::json) 'fat':2 'rat':3 + + + json(b)_to_tsvector( config regconfig, + document json(b), + filter json(b)) + + tsvector + + reduce each value in the document, specified by filter to a tsvector, + and then concatenate those in document order to produce a single tsvector. + filter is a jsonb array, that enumerates what kind of elements need to be included + into the resulting tsvector. Possible values for filter are + "string" (to include all string values), "numeric" (to include all numeric values in the string format), + "boolean" (to include all boolean values in the string format "true"/"false"), + "key" (to include all keys) or "all" (to include all above). These values + can be combined together to include, e.g. all string and numeric values. + + json_to_tsvector('english', '{"a": "The Fat Rats", "b": 123}'::json, '["string", "numeric"]') + '123':5 'fat':2 'rat':3 + -- cgit v1.2.3