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 --- src/include/utils/jsonapi.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/include/utils/jsonapi.h') diff --git a/src/include/utils/jsonapi.h b/src/include/utils/jsonapi.h index e39572e00f..b28201c2bc 100644 --- a/src/include/utils/jsonapi.h +++ b/src/include/utils/jsonapi.h @@ -132,15 +132,28 @@ extern JsonLexContext *makeJsonLexContextCstringLen(char *json, */ extern bool IsValidJsonNumber(const char *str, int len); -/* an action that will be applied to each value in iterate_json(b)_string_vaues functions */ +/* + * Flag types for iterate_json(b)_values to specify what elements from a + * json(b) document we want to iterate. + */ +typedef enum JsonToIndex { + jtiKey = 0x01, + jtiString = 0x02, + jtiNumeric = 0x04, + jtiBool = 0x08, + jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool +} JsonToIndex; + +/* an action that will be applied to each value in iterate_json(b)_vaues functions */ typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len); -/* an action that will be applied to each value in transform_json(b)_string_values functions */ +/* an action that will be applied to each value in transform_json(b)_values functions */ typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len); -extern void iterate_jsonb_string_values(Jsonb *jb, void *state, +extern uint32 parse_jsonb_index_flags(Jsonb *jb); +extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action); -extern void iterate_json_string_values(text *json, void *action_state, +extern void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action); extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action); -- cgit v1.2.1