PostgreSQL Source Code  git master
wparser.c File Reference
#include "postgres.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
#include "common/jsonapi.h"
#include "funcapi.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/jsonfuncs.h"
#include "utils/varlena.h"
Include dependency graph for wparser.c:

Go to the source code of this file.

Data Structures

struct  TSTokenTypeStorage
 
struct  HeadlineJsonState
 
struct  LexemeEntry
 
struct  PrsStorage
 

Typedefs

typedef struct HeadlineJsonState HeadlineJsonState
 

Functions

static textheadline_json_value (void *_state, char *elem_value, int elem_len)
 
static void tt_setup_firstcall (FuncCallContext *funcctx, FunctionCallInfo fcinfo, Oid prsid)
 
static Datum tt_process_call (FuncCallContext *funcctx)
 
Datum ts_token_type_byid (PG_FUNCTION_ARGS)
 
Datum ts_token_type_byname (PG_FUNCTION_ARGS)
 
static void prs_setup_firstcall (FuncCallContext *funcctx, FunctionCallInfo fcinfo, Oid prsid, text *txt)
 
static Datum prs_process_call (FuncCallContext *funcctx)
 
Datum ts_parse_byid (PG_FUNCTION_ARGS)
 
Datum ts_parse_byname (PG_FUNCTION_ARGS)
 
Datum ts_headline_byid_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_byid (PG_FUNCTION_ARGS)
 
Datum ts_headline (PG_FUNCTION_ARGS)
 
Datum ts_headline_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_jsonb_byid_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_jsonb (PG_FUNCTION_ARGS)
 
Datum ts_headline_jsonb_byid (PG_FUNCTION_ARGS)
 
Datum ts_headline_jsonb_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_json_byid_opt (PG_FUNCTION_ARGS)
 
Datum ts_headline_json (PG_FUNCTION_ARGS)
 
Datum ts_headline_json_byid (PG_FUNCTION_ARGS)
 
Datum ts_headline_json_opt (PG_FUNCTION_ARGS)
 

Typedef Documentation

◆ HeadlineJsonState

Function Documentation

◆ headline_json_value()

static text * headline_json_value ( void *  _state,
char *  elem_value,
int  elem_len 
)
static

Definition at line 525 of file wparser.c.

526 {
528 
529  HeadlineParsedText *prs = state->prs;
530  TSConfigCacheEntry *cfg = state->cfg;
531  TSParserCacheEntry *prsobj = state->prsobj;
532  TSQuery query = state->query;
533  List *prsoptions = state->prsoptions;
534 
535  prs->curwords = 0;
536  hlparsetext(cfg->cfgId, prs, query, elem_value, elem_len);
537  FunctionCall3(&(prsobj->prsheadline),
538  PointerGetDatum(prs),
539  PointerGetDatum(prsoptions),
540  PointerGetDatum(query));
541 
542  state->transformed = true;
543  return generateHeadline(prs);
544 }
#define FunctionCall3(flinfo, arg1, arg2, arg3)
Definition: fmgr.h:664
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
Definition: pg_list.h:54
FmgrInfo prsheadline
Definition: ts_cache.h:48
Definition: regguts.h:323
void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query, char *buf, int buflen)
Definition: ts_parse.c:540
text * generateHeadline(HeadlineParsedText *prs)
Definition: ts_parse.c:607

References TSConfigCacheEntry::cfgId, HeadlineParsedText::curwords, FunctionCall3, generateHeadline(), hlparsetext(), PointerGetDatum(), and TSParserCacheEntry::prsheadline.

Referenced by ts_headline_json_byid_opt(), and ts_headline_jsonb_byid_opt().

◆ prs_process_call()

static Datum prs_process_call ( FuncCallContext funcctx)
static

Definition at line 218 of file wparser.c.

219 {
220  PrsStorage *st;
221 
222  st = (PrsStorage *) funcctx->user_fctx;
223  if (st->cur < st->len)
224  {
225  Datum result;
226  char *values[2];
227  char tid[16];
228  HeapTuple tuple;
229 
230  values[0] = tid;
231  sprintf(tid, "%d", st->list[st->cur].type);
232  values[1] = st->list[st->cur].lexeme;
233  tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
234  result = HeapTupleGetDatum(tuple);
235 
236  pfree(values[1]);
237  st->cur++;
238  return result;
239  }
240  return (Datum) 0;
241 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2136
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
void pfree(void *pointer)
Definition: mcxt.c:1456
#define sprintf
Definition: port.h:240
uintptr_t Datum
Definition: postgres.h:64
void * user_fctx
Definition: funcapi.h:82
AttInMetadata * attinmeta
Definition: funcapi.h:91
int type
Definition: wparser.c:151
char * lexeme
Definition: wparser.c:152
int len
Definition: wparser.c:158
int cur
Definition: wparser.c:157
LexemeEntry * list
Definition: wparser.c:159

References FuncCallContext::attinmeta, BuildTupleFromCStrings(), PrsStorage::cur, HeapTupleGetDatum(), if(), PrsStorage::len, LexemeEntry::lexeme, PrsStorage::list, pfree(), sprintf, LexemeEntry::type, FuncCallContext::user_fctx, and values.

Referenced by ts_parse_byid(), and ts_parse_byname().

◆ prs_setup_firstcall()

static void prs_setup_firstcall ( FuncCallContext funcctx,
FunctionCallInfo  fcinfo,
Oid  prsid,
text txt 
)
static

Definition at line 164 of file wparser.c.

166 {
167  TupleDesc tupdesc;
168  MemoryContext oldcontext;
169  PrsStorage *st;
171  char *lex = NULL;
172  int llen = 0,
173  type = 0;
174  void *prsdata;
175 
176  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
177 
178  st = (PrsStorage *) palloc(sizeof(PrsStorage));
179  st->cur = 0;
180  st->len = 16;
181  st->list = (LexemeEntry *) palloc(sizeof(LexemeEntry) * st->len);
182 
183  prsdata = (void *) DatumGetPointer(FunctionCall2(&prs->prsstart,
186 
187  while ((type = DatumGetInt32(FunctionCall3(&prs->prstoken,
188  PointerGetDatum(prsdata),
189  PointerGetDatum(&lex),
190  PointerGetDatum(&llen)))) != 0)
191  {
192  if (st->cur >= st->len)
193  {
194  st->len = 2 * st->len;
195  st->list = (LexemeEntry *) repalloc(st->list, sizeof(LexemeEntry) * st->len);
196  }
197  st->list[st->cur].lexeme = palloc(llen + 1);
198  memcpy(st->list[st->cur].lexeme, lex, llen);
199  st->list[st->cur].lexeme[llen] = '\0';
200  st->list[st->cur].type = type;
201  st->cur++;
202  }
203 
204  FunctionCall1(&prs->prsend, PointerGetDatum(prsdata));
205 
206  st->len = st->cur;
207  st->cur = 0;
208 
209  funcctx->user_fctx = (void *) st;
210  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
211  elog(ERROR, "return type must be a row type");
212  funcctx->tuple_desc = tupdesc;
213  funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
214  MemoryContextSwitchTo(oldcontext);
215 }
#define ERROR
Definition: elog.h:39
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2087
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:660
#define FunctionCall2(flinfo, arg1, arg2)
Definition: fmgr.h:662
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1476
void * palloc(Size size)
Definition: mcxt.c:1226
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
TupleDesc tuple_desc
Definition: funcapi.h:112
FmgrInfo prstoken
Definition: ts_cache.h:46
FmgrInfo prsstart
Definition: ts_cache.h:45
FmgrInfo prsend
Definition: ts_cache.h:47
TSParserCacheEntry * lookup_ts_parser_cache(Oid prsId)
Definition: ts_cache.c:113
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References FuncCallContext::attinmeta, PrsStorage::cur, DatumGetInt32(), DatumGetPointer(), elog(), ERROR, FunctionCall1, FunctionCall2, FunctionCall3, get_call_result_type(), Int32GetDatum(), PrsStorage::len, LexemeEntry::lexeme, PrsStorage::list, lookup_ts_parser_cache(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), PointerGetDatum(), TSParserCacheEntry::prsend, TSParserCacheEntry::prsstart, TSParserCacheEntry::prstoken, repalloc(), FuncCallContext::tuple_desc, TupleDescGetAttInMetadata(), generate_unaccent_rules::type, LexemeEntry::type, TYPEFUNC_COMPOSITE, FuncCallContext::user_fctx, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by ts_parse_byid(), and ts_parse_byname().

◆ ts_headline()

Datum ts_headline ( PG_FUNCTION_ARGS  )

Definition at line 350 of file wparser.c.

351 {
354  PG_GETARG_DATUM(0),
355  PG_GETARG_DATUM(1)));
356 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:646
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
Datum ts_headline_byid_opt(PG_FUNCTION_ARGS)
Definition: wparser.c:290

References DirectFunctionCall3, getTSCurrentConfig(), ObjectIdGetDatum(), PG_GETARG_DATUM, PG_RETURN_DATUM, and ts_headline_byid_opt().

◆ ts_headline_byid()

Datum ts_headline_byid ( PG_FUNCTION_ARGS  )

◆ ts_headline_byid_opt()

Datum ts_headline_byid_opt ( PG_FUNCTION_ARGS  )

Definition at line 290 of file wparser.c.

291 {
292  Oid tsconfig = PG_GETARG_OID(0);
293  text *in = PG_GETARG_TEXT_PP(1);
294  TSQuery query = PG_GETARG_TSQUERY(2);
295  text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_PP(3) : NULL;
296  HeadlineParsedText prs;
297  List *prsoptions;
298  text *out;
299  TSConfigCacheEntry *cfg;
300  TSParserCacheEntry *prsobj;
301 
302  cfg = lookup_ts_config_cache(tsconfig);
303  prsobj = lookup_ts_parser_cache(cfg->prsId);
304 
305  if (!OidIsValid(prsobj->headlineOid))
306  ereport(ERROR,
307  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
308  errmsg("text search parser does not support headline creation")));
309 
310  memset(&prs, 0, sizeof(HeadlineParsedText));
311  prs.lenwords = 32;
312  prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
313 
314  hlparsetext(cfg->cfgId, &prs, query,
315  VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in));
316 
317  if (opt)
318  prsoptions = deserialize_deflist(PointerGetDatum(opt));
319  else
320  prsoptions = NIL;
321 
322  FunctionCall3(&(prsobj->prsheadline),
323  PointerGetDatum(&prs),
324  PointerGetDatum(prsoptions),
325  PointerGetDatum(query));
326 
327  out = generateHeadline(&prs);
328 
329  PG_FREE_IF_COPY(in, 1);
330  PG_FREE_IF_COPY(query, 2);
331  if (opt)
332  PG_FREE_IF_COPY(opt, 3);
333  pfree(prs.words);
334  pfree(prs.startsel);
335  pfree(prs.stopsel);
336 
337  PG_RETURN_POINTER(out);
338 }
#define OidIsValid(objectId)
Definition: c.h:759
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_NARGS()
Definition: fmgr.h:203
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define NIL
Definition: pg_list.h:68
unsigned int Oid
Definition: postgres_ext.h:31
HeadlineWordEntry * words
Definition: ts_public.h:76
Definition: c.h:671
TSConfigCacheEntry * lookup_ts_config_cache(Oid cfgId)
Definition: ts_cache.c:385
#define PG_GETARG_TSQUERY(n)
Definition: ts_type.h:266
List * deserialize_deflist(Datum txt)
Definition: tsearchcmds.c:1584

References TSConfigCacheEntry::cfgId, deserialize_deflist(), ereport, errcode(), errmsg(), ERROR, FunctionCall3, generateHeadline(), TSParserCacheEntry::headlineOid, hlparsetext(), HeadlineParsedText::lenwords, lookup_ts_config_cache(), lookup_ts_parser_cache(), NIL, OidIsValid, palloc(), pfree(), PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_TEXT_PP, PG_GETARG_TSQUERY, PG_NARGS, PG_RETURN_POINTER, PointerGetDatum(), TSParserCacheEntry::prsheadline, TSConfigCacheEntry::prsId, HeadlineParsedText::startsel, HeadlineParsedText::stopsel, VARDATA_ANY, VARSIZE_ANY_EXHDR, and HeadlineParsedText::words.

Referenced by ts_headline(), ts_headline_byid(), and ts_headline_opt().

◆ ts_headline_json()

Datum ts_headline_json ( PG_FUNCTION_ARGS  )

◆ ts_headline_json_byid()

Datum ts_headline_json_byid ( PG_FUNCTION_ARGS  )

◆ ts_headline_json_byid_opt()

Datum ts_headline_json_byid_opt ( PG_FUNCTION_ARGS  )

Definition at line 445 of file wparser.c.

446 {
447  Oid tsconfig = PG_GETARG_OID(0);
448  text *json = PG_GETARG_TEXT_P(1);
449  TSQuery query = PG_GETARG_TSQUERY(2);
450  text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL;
451  text *out;
453 
454  HeadlineParsedText prs;
456 
457  memset(&prs, 0, sizeof(HeadlineParsedText));
458  prs.lenwords = 32;
459  prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
460 
461  state->prs = &prs;
462  state->cfg = lookup_ts_config_cache(tsconfig);
463  state->prsobj = lookup_ts_parser_cache(state->cfg->prsId);
464  state->query = query;
465  if (opt)
466  state->prsoptions = deserialize_deflist(PointerGetDatum(opt));
467  else
468  state->prsoptions = NIL;
469 
470  if (!OidIsValid(state->prsobj->headlineOid))
471  ereport(ERROR,
472  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
473  errmsg("text search parser does not support headline creation")));
474 
476 
477  PG_FREE_IF_COPY(json, 1);
478  PG_FREE_IF_COPY(query, 2);
479  if (opt)
480  PG_FREE_IF_COPY(opt, 3);
481  pfree(prs.words);
482 
483  if (state->transformed)
484  {
485  pfree(prs.startsel);
486  pfree(prs.stopsel);
487  }
488 
489  PG_RETURN_TEXT_P(out);
490 }
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5552
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition: jsonfuncs.h:37
void * palloc0(Size size)
Definition: mcxt.c:1257
static text * headline_json_value(void *_state, char *elem_value, int elem_len)
Definition: wparser.c:525

References generate_unaccent_rules::action, deserialize_deflist(), ereport, errcode(), errmsg(), ERROR, headline_json_value(), HeadlineParsedText::lenwords, lookup_ts_config_cache(), lookup_ts_parser_cache(), NIL, OidIsValid, palloc(), palloc0(), pfree(), PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_TEXT_P, PG_GETARG_TSQUERY, PG_NARGS, PG_RETURN_TEXT_P, PointerGetDatum(), HeadlineParsedText::startsel, HeadlineParsedText::stopsel, transform_json_string_values(), and HeadlineParsedText::words.

Referenced by ts_headline_json(), ts_headline_json_byid(), and ts_headline_json_opt().

◆ ts_headline_json_opt()

Datum ts_headline_json_opt ( PG_FUNCTION_ARGS  )

Definition at line 511 of file wparser.c.

512 {
515  PG_GETARG_DATUM(0),
516  PG_GETARG_DATUM(1),
517  PG_GETARG_DATUM(2)));
518 }
#define DirectFunctionCall4(func, arg1, arg2, arg3, arg4)
Definition: fmgr.h:648

References DirectFunctionCall4, getTSCurrentConfig(), ObjectIdGetDatum(), PG_GETARG_DATUM, PG_RETURN_DATUM, and ts_headline_json_byid_opt().

◆ ts_headline_jsonb()

Datum ts_headline_jsonb ( PG_FUNCTION_ARGS  )

◆ ts_headline_jsonb_byid()

Datum ts_headline_jsonb_byid ( PG_FUNCTION_ARGS  )

◆ ts_headline_jsonb_byid_opt()

Datum ts_headline_jsonb_byid_opt ( PG_FUNCTION_ARGS  )

Definition at line 369 of file wparser.c.

370 {
371  Oid tsconfig = PG_GETARG_OID(0);
372  Jsonb *jb = PG_GETARG_JSONB_P(1);
373  TSQuery query = PG_GETARG_TSQUERY(2);
374  text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL;
375  Jsonb *out;
377  HeadlineParsedText prs;
379 
380  memset(&prs, 0, sizeof(HeadlineParsedText));
381  prs.lenwords = 32;
382  prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
383 
384  state->prs = &prs;
385  state->cfg = lookup_ts_config_cache(tsconfig);
386  state->prsobj = lookup_ts_parser_cache(state->cfg->prsId);
387  state->query = query;
388  if (opt)
389  state->prsoptions = deserialize_deflist(PointerGetDatum(opt));
390  else
391  state->prsoptions = NIL;
392 
393  if (!OidIsValid(state->prsobj->headlineOid))
394  ereport(ERROR,
395  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
396  errmsg("text search parser does not support headline creation")));
397 
399 
400  PG_FREE_IF_COPY(jb, 1);
401  PG_FREE_IF_COPY(query, 2);
402  if (opt)
403  PG_FREE_IF_COPY(opt, 3);
404 
405  pfree(prs.words);
406 
407  if (state->transformed)
408  {
409  pfree(prs.startsel);
410  pfree(prs.stopsel);
411  }
412 
413  PG_RETURN_JSONB_P(out);
414 }
#define PG_RETURN_JSONB_P(x)
Definition: jsonb.h:393
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:391
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5505
Definition: jsonb.h:213

References generate_unaccent_rules::action, deserialize_deflist(), ereport, errcode(), errmsg(), ERROR, headline_json_value(), HeadlineParsedText::lenwords, lookup_ts_config_cache(), lookup_ts_parser_cache(), NIL, OidIsValid, palloc(), palloc0(), pfree(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_TEXT_P, PG_GETARG_TSQUERY, PG_NARGS, PG_RETURN_JSONB_P, PointerGetDatum(), HeadlineParsedText::startsel, HeadlineParsedText::stopsel, transform_jsonb_string_values(), and HeadlineParsedText::words.

Referenced by ts_headline_jsonb(), ts_headline_jsonb_byid(), and ts_headline_jsonb_opt().

◆ ts_headline_jsonb_opt()

◆ ts_headline_opt()

◆ ts_parse_byid()

Datum ts_parse_byid ( PG_FUNCTION_ARGS  )

Definition at line 244 of file wparser.c.

245 {
246  FuncCallContext *funcctx;
247  Datum result;
248 
249  if (SRF_IS_FIRSTCALL())
250  {
251  text *txt = PG_GETARG_TEXT_PP(1);
252 
253  funcctx = SRF_FIRSTCALL_INIT();
254  prs_setup_firstcall(funcctx, fcinfo, PG_GETARG_OID(0), txt);
255  PG_FREE_IF_COPY(txt, 1);
256  }
257 
258  funcctx = SRF_PERCALL_SETUP();
259 
260  if ((result = prs_process_call(funcctx)) != (Datum) 0)
261  SRF_RETURN_NEXT(funcctx, result);
262  SRF_RETURN_DONE(funcctx);
263 }
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
static void prs_setup_firstcall(FuncCallContext *funcctx, FunctionCallInfo fcinfo, Oid prsid, text *txt)
Definition: wparser.c:164
static Datum prs_process_call(FuncCallContext *funcctx)
Definition: wparser.c:218

References PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_TEXT_PP, prs_process_call(), prs_setup_firstcall(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, and SRF_RETURN_NEXT.

◆ ts_parse_byname()

Datum ts_parse_byname ( PG_FUNCTION_ARGS  )

Definition at line 266 of file wparser.c.

267 {
268  FuncCallContext *funcctx;
269  Datum result;
270 
271  if (SRF_IS_FIRSTCALL())
272  {
273  text *prsname = PG_GETARG_TEXT_PP(0);
274  text *txt = PG_GETARG_TEXT_PP(1);
275  Oid prsId;
276 
277  funcctx = SRF_FIRSTCALL_INIT();
278  prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
279  prs_setup_firstcall(funcctx, fcinfo, prsId, txt);
280  }
281 
282  funcctx = SRF_PERCALL_SETUP();
283 
284  if ((result = prs_process_call(funcctx)) != (Datum) 0)
285  SRF_RETURN_NEXT(funcctx, result);
286  SRF_RETURN_DONE(funcctx);
287 }
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2343
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3396

References get_ts_parser_oid(), PG_GETARG_TEXT_PP, prs_process_call(), prs_setup_firstcall(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, and textToQualifiedNameList().

◆ ts_token_type_byid()

Datum ts_token_type_byid ( PG_FUNCTION_ARGS  )

Definition at line 108 of file wparser.c.

109 {
110  FuncCallContext *funcctx;
111  Datum result;
112 
113  if (SRF_IS_FIRSTCALL())
114  {
115  funcctx = SRF_FIRSTCALL_INIT();
116  tt_setup_firstcall(funcctx, fcinfo, PG_GETARG_OID(0));
117  }
118 
119  funcctx = SRF_PERCALL_SETUP();
120 
121  if ((result = tt_process_call(funcctx)) != (Datum) 0)
122  SRF_RETURN_NEXT(funcctx, result);
123  SRF_RETURN_DONE(funcctx);
124 }
static void tt_setup_firstcall(FuncCallContext *funcctx, FunctionCallInfo fcinfo, Oid prsid)
Definition: wparser.c:49
static Datum tt_process_call(FuncCallContext *funcctx)
Definition: wparser.c:79

References PG_GETARG_OID, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, tt_process_call(), and tt_setup_firstcall().

◆ ts_token_type_byname()

Datum ts_token_type_byname ( PG_FUNCTION_ARGS  )

Definition at line 127 of file wparser.c.

128 {
129  FuncCallContext *funcctx;
130  Datum result;
131 
132  if (SRF_IS_FIRSTCALL())
133  {
134  text *prsname = PG_GETARG_TEXT_PP(0);
135  Oid prsId;
136 
137  funcctx = SRF_FIRSTCALL_INIT();
138  prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
139  tt_setup_firstcall(funcctx, fcinfo, prsId);
140  }
141 
142  funcctx = SRF_PERCALL_SETUP();
143 
144  if ((result = tt_process_call(funcctx)) != (Datum) 0)
145  SRF_RETURN_NEXT(funcctx, result);
146  SRF_RETURN_DONE(funcctx);
147 }

References get_ts_parser_oid(), PG_GETARG_TEXT_PP, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, textToQualifiedNameList(), tt_process_call(), and tt_setup_firstcall().

◆ tt_process_call()

static Datum tt_process_call ( FuncCallContext funcctx)
static

Definition at line 79 of file wparser.c.

80 {
82 
83  st = (TSTokenTypeStorage *) funcctx->user_fctx;
84  if (st->list && st->list[st->cur].lexid)
85  {
86  Datum result;
87  char *values[3];
88  char txtid[16];
89  HeapTuple tuple;
90 
91  sprintf(txtid, "%d", st->list[st->cur].lexid);
92  values[0] = txtid;
93  values[1] = st->list[st->cur].alias;
94  values[2] = st->list[st->cur].descr;
95 
96  tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
97  result = HeapTupleGetDatum(tuple);
98 
99  pfree(values[1]);
100  pfree(values[2]);
101  st->cur++;
102  return result;
103  }
104  return (Datum) 0;
105 }
char * alias
Definition: ts_public.h:28
int lexid
Definition: ts_public.h:27
char * descr
Definition: ts_public.h:29
LexDescr * list
Definition: wparser.c:32

References LexDescr::alias, FuncCallContext::attinmeta, BuildTupleFromCStrings(), TSTokenTypeStorage::cur, LexDescr::descr, HeapTupleGetDatum(), if(), LexDescr::lexid, TSTokenTypeStorage::list, pfree(), sprintf, FuncCallContext::user_fctx, and values.

Referenced by ts_token_type_byid(), and ts_token_type_byname().

◆ tt_setup_firstcall()

static void tt_setup_firstcall ( FuncCallContext funcctx,
FunctionCallInfo  fcinfo,
Oid  prsid 
)
static

Definition at line 49 of file wparser.c.

51 {
52  TupleDesc tupdesc;
53  MemoryContext oldcontext;
56 
57  if (!OidIsValid(prs->lextypeOid))
58  elog(ERROR, "method lextype isn't defined for text search parser %u",
59  prsid);
60 
61  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
62 
64  st->cur = 0;
65  /* lextype takes one dummy argument */
67  (Datum) 0));
68  funcctx->user_fctx = (void *) st;
69 
70  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
71  elog(ERROR, "return type must be a row type");
72  funcctx->tuple_desc = tupdesc;
73  funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
74 
75  MemoryContextSwitchTo(oldcontext);
76 }
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:680

References FuncCallContext::attinmeta, TSTokenTypeStorage::cur, DatumGetPointer(), elog(), ERROR, get_call_result_type(), TSParserCacheEntry::lextypeOid, TSTokenTypeStorage::list, lookup_ts_parser_cache(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, OidFunctionCall1, OidIsValid, palloc(), FuncCallContext::tuple_desc, TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, and FuncCallContext::user_fctx.

Referenced by ts_token_type_byid(), and ts_token_type_byname().