@@ -267,12 +267,12 @@ to_tsvector(PG_FUNCTION_ARGS)
267
267
PointerGetDatum (in )));
268
268
}
269
269
270
- Datum
271
- jsonb_to_tsvector_byid (PG_FUNCTION_ARGS )
270
+ /*
271
+ * Worker function for jsonb(_string)_to_tsvector(_byid)
272
+ */
273
+ static TSVector
274
+ jsonb_to_tsvector_worker (Oid cfgId , Jsonb * jb , uint32 flags )
272
275
{
273
- Oid cfgId = PG_GETARG_OID (0 );
274
- Jsonb * jb = PG_GETARG_JSONB_P (1 );
275
- TSVector result ;
276
276
TSVectorBuildState state ;
277
277
ParsedText prs ;
278
278
@@ -281,33 +281,77 @@ jsonb_to_tsvector_byid(PG_FUNCTION_ARGS)
281
281
state .prs = & prs ;
282
282
state .cfgId = cfgId ;
283
283
284
- iterate_jsonb_string_values (jb , & state , add_to_tsvector );
284
+ iterate_jsonb_values (jb , flags , & state , add_to_tsvector );
285
285
286
- PG_FREE_IF_COPY (jb , 1 );
286
+ return make_tsvector (& prs );
287
+ }
288
+
289
+ Datum
290
+ jsonb_string_to_tsvector_byid (PG_FUNCTION_ARGS )
291
+ {
292
+ Oid cfgId = PG_GETARG_OID (0 );
293
+ Jsonb * jb = PG_GETARG_JSONB_P (1 );
294
+ TSVector result ;
287
295
288
- result = make_tsvector (& prs );
296
+ result = jsonb_to_tsvector_worker (cfgId , jb , jtiString );
297
+ PG_FREE_IF_COPY (jb , 1 );
289
298
290
299
PG_RETURN_TSVECTOR (result );
291
300
}
292
301
293
302
Datum
294
- jsonb_to_tsvector (PG_FUNCTION_ARGS )
303
+ jsonb_string_to_tsvector (PG_FUNCTION_ARGS )
295
304
{
296
305
Jsonb * jb = PG_GETARG_JSONB_P (0 );
297
306
Oid cfgId ;
307
+ TSVector result ;
298
308
299
309
cfgId = getTSCurrentConfig (true);
300
- PG_RETURN_DATUM (DirectFunctionCall2 (jsonb_to_tsvector_byid ,
301
- ObjectIdGetDatum (cfgId ),
302
- JsonbPGetDatum (jb )));
310
+ result = jsonb_to_tsvector_worker (cfgId , jb , jtiString );
311
+ PG_FREE_IF_COPY (jb , 0 );
312
+
313
+ PG_RETURN_TSVECTOR (result );
303
314
}
304
315
305
316
Datum
306
- json_to_tsvector_byid (PG_FUNCTION_ARGS )
317
+ jsonb_to_tsvector_byid (PG_FUNCTION_ARGS )
307
318
{
308
319
Oid cfgId = PG_GETARG_OID (0 );
309
- text * json = PG_GETARG_TEXT_P (1 );
320
+ Jsonb * jb = PG_GETARG_JSONB_P (1 );
321
+ Jsonb * jbFlags = PG_GETARG_JSONB_P (2 );
322
+ TSVector result ;
323
+ uint32 flags = parse_jsonb_index_flags (jbFlags );
324
+
325
+ result = jsonb_to_tsvector_worker (cfgId , jb , flags );
326
+ PG_FREE_IF_COPY (jb , 1 );
327
+ PG_FREE_IF_COPY (jbFlags , 2 );
328
+
329
+ PG_RETURN_TSVECTOR (result );
330
+ }
331
+
332
+ Datum
333
+ jsonb_to_tsvector (PG_FUNCTION_ARGS )
334
+ {
335
+ Jsonb * jb = PG_GETARG_JSONB_P (0 );
336
+ Jsonb * jbFlags = PG_GETARG_JSONB_P (1 );
337
+ Oid cfgId ;
310
338
TSVector result ;
339
+ uint32 flags = parse_jsonb_index_flags (jbFlags );
340
+
341
+ cfgId = getTSCurrentConfig (true);
342
+ result = jsonb_to_tsvector_worker (cfgId , jb , flags );
343
+ PG_FREE_IF_COPY (jb , 0 );
344
+ PG_FREE_IF_COPY (jbFlags , 1 );
345
+
346
+ PG_RETURN_TSVECTOR (result );
347
+ }
348
+
349
+ /*
350
+ * Worker function for json(_string)_to_tsvector(_byid)
351
+ */
352
+ static TSVector
353
+ json_to_tsvector_worker (Oid cfgId , text * json , uint32 flags )
354
+ {
311
355
TSVectorBuildState state ;
312
356
ParsedText prs ;
313
357
@@ -316,11 +360,50 @@ json_to_tsvector_byid(PG_FUNCTION_ARGS)
316
360
state .prs = & prs ;
317
361
state .cfgId = cfgId ;
318
362
319
- iterate_json_string_values (json , & state , add_to_tsvector );
363
+ iterate_json_values (json , flags , & state , add_to_tsvector );
364
+
365
+ return make_tsvector (& prs );
366
+ }
367
+
368
+ Datum
369
+ json_string_to_tsvector_byid (PG_FUNCTION_ARGS )
370
+ {
371
+ Oid cfgId = PG_GETARG_OID (0 );
372
+ text * json = PG_GETARG_TEXT_P (1 );
373
+ TSVector result ;
320
374
375
+ result = json_to_tsvector_worker (cfgId , json , jtiString );
321
376
PG_FREE_IF_COPY (json , 1 );
322
377
323
- result = make_tsvector (& prs );
378
+ PG_RETURN_TSVECTOR (result );
379
+ }
380
+
381
+ Datum
382
+ json_string_to_tsvector (PG_FUNCTION_ARGS )
383
+ {
384
+ text * json = PG_GETARG_TEXT_P (0 );
385
+ Oid cfgId ;
386
+ TSVector result ;
387
+
388
+ cfgId = getTSCurrentConfig (true);
389
+ result = json_to_tsvector_worker (cfgId , json , jtiString );
390
+ PG_FREE_IF_COPY (json , 0 );
391
+
392
+ PG_RETURN_TSVECTOR (result );
393
+ }
394
+
395
+ Datum
396
+ json_to_tsvector_byid (PG_FUNCTION_ARGS )
397
+ {
398
+ Oid cfgId = PG_GETARG_OID (0 );
399
+ text * json = PG_GETARG_TEXT_P (1 );
400
+ Jsonb * jbFlags = PG_GETARG_JSONB_P (2 );
401
+ TSVector result ;
402
+ uint32 flags = parse_jsonb_index_flags (jbFlags );
403
+
404
+ result = json_to_tsvector_worker (cfgId , json , flags );
405
+ PG_FREE_IF_COPY (json , 1 );
406
+ PG_FREE_IF_COPY (jbFlags , 2 );
324
407
325
408
PG_RETURN_TSVECTOR (result );
326
409
}
@@ -329,12 +412,17 @@ Datum
329
412
json_to_tsvector (PG_FUNCTION_ARGS )
330
413
{
331
414
text * json = PG_GETARG_TEXT_P (0 );
415
+ Jsonb * jbFlags = PG_GETARG_JSONB_P (1 );
332
416
Oid cfgId ;
417
+ TSVector result ;
418
+ uint32 flags = parse_jsonb_index_flags (jbFlags );
333
419
334
420
cfgId = getTSCurrentConfig (true);
335
- PG_RETURN_DATUM (DirectFunctionCall2 (json_to_tsvector_byid ,
336
- ObjectIdGetDatum (cfgId ),
337
- PointerGetDatum (json )));
421
+ result = json_to_tsvector_worker (cfgId , json , flags );
422
+ PG_FREE_IF_COPY (json , 0 );
423
+ PG_FREE_IF_COPY (jbFlags , 1 );
424
+
425
+ PG_RETURN_TSVECTOR (result );
338
426
}
339
427
340
428
/*
@@ -353,7 +441,7 @@ add_to_tsvector(void *_state, char *elem_value, int elem_len)
353
441
* First time through: initialize words array to a reasonable size.
354
442
* (parsetext() will realloc it bigger as needed.)
355
443
*/
356
- prs -> lenwords = Max ( elem_len / 6 , 64 ) ;
444
+ prs -> lenwords = 16 ;
357
445
prs -> words = (ParsedWord * ) palloc (sizeof (ParsedWord ) * prs -> lenwords );
358
446
prs -> curwords = 0 ;
359
447
prs -> pos = 0 ;
0 commit comments