1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

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
This commit is contained in:
Teodor Sigaev
2018-04-07 20:58:03 +03:00
parent 529ab7bd1f
commit 1c1791e000
10 changed files with 630 additions and 50 deletions

View File

@ -9727,6 +9727,26 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
<entry><literal>to_tsvector('english', '{"a": "The Fat Rats"}'::json)</literal></entry>
<entry><literal>'fat':2 'rat':3</literal></entry>
</row>
<row>
<entry>
<literal><function>json(b)_to_tsvector(<optional> <replaceable class="parameter">config</replaceable> <type>regconfig</type>,
</optional> <replaceable class="parameter">document</replaceable> <type>json(b)</type>,
<replaceable class="parameter">filter</replaceable> <type>json(b)</type>)</function></literal>
</entry>
<entry><type>tsvector</type></entry>
<entry>
reduce each value in the document, specified by <replaceable class="parameter">filter</replaceable> to a <type>tsvector</type>,
and then concatenate those in document order to produce a single <type>tsvector</type>.
<replaceable class="parameter">filter</replaceable> is a jsonb array, that enumerates what kind of elements need to be included
into the resulting <type>tsvector</type>. Possible values for <replaceable class="parameter">filter</replaceable> are
<literal>"string"</literal> (to include all string values), <literal>"numeric"</literal> (to include all numeric values in the string format),
<literal>"boolean"</literal> (to include all boolean values in the string format "true"/"false"),
<literal>"key"</literal> (to include all keys) or <literal>"all"</literal> (to include all above). These values
can be combined together to include, e.g. all string and numeric values.
</entry>
<entry><literal>json_to_tsvector('english', '{"a": "The Fat Rats", "b": 123}'::json, '["string", "numeric"]')</literal></entry>
<entry><literal>'123':5 'fat':2 'rat':3</literal></entry>
</row>
<row>
<entry>
<indexterm>