PostgreSQL Source Code  git master
dict.c File Reference
#include "postgres.h"
#include "catalog/pg_type.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
Include dependency graph for dict.c:

Go to the source code of this file.

Functions

Datum ts_lexize (PG_FUNCTION_ARGS)
 

Function Documentation

◆ ts_lexize()

Datum ts_lexize ( PG_FUNCTION_ARGS  )

Definition at line 26 of file dict.c.

References construct_array(), CStringGetTextDatum, DatumGetPointer, TSDictionaryCacheEntry::dictData, FunctionCall4, DictSubState::getnext, Int32GetDatum, DictSubState::isend, TSLexeme::lexeme, TSDictionaryCacheEntry::lexize, lookup_ts_dictionary_cache(), palloc(), pfree(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_POINTER, PointerGetDatum, TEXTOID, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

27 {
28  Oid dictId = PG_GETARG_OID(0);
29  text *in = PG_GETARG_TEXT_PP(1);
30  ArrayType *a;
32  TSLexeme *res,
33  *ptr;
34  Datum *da;
35  DictSubState dstate = {false, false, NULL};
36 
37  dict = lookup_ts_dictionary_cache(dictId);
38 
43  PointerGetDatum(&dstate)));
44 
45  if (dstate.getnext)
46  {
47  dstate.isend = true;
52  PointerGetDatum(&dstate)));
53  if (ptr != NULL)
54  res = ptr;
55  }
56 
57  if (!res)
59 
60  ptr = res;
61  while (ptr->lexeme)
62  ptr++;
63  da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
64  ptr = res;
65  while (ptr->lexeme)
66  {
67  da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
68  ptr++;
69  }
70 
71  a = construct_array(da,
72  ptr - res,
73  TEXTOID,
74  -1,
75  false,
76  'i');
77 
78  ptr = res;
79  while (ptr->lexeme)
80  {
81  pfree(DatumGetPointer(da[ptr - res]));
82  pfree(ptr->lexeme);
83  ptr++;
84  }
85  pfree(res);
86  pfree(da);
87 
89 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define TEXTOID
Definition: pg_type.h:324
#define PointerGetDatum(X)
Definition: postgres.h:562
bool getnext
Definition: ts_public.h:127
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3279
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
Definition: ts_cache.c:210
void pfree(void *pointer)
Definition: mcxt.c:949
char * lexeme
Definition: ts_public.h:111
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
Definition: fmgr.h:609
uintptr_t Datum
Definition: postgres.h:372
#define DatumGetPointer(X)
Definition: postgres.h:555
#define Int32GetDatum(X)
Definition: postgres.h:485
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:848
#define CStringGetTextDatum(s)
Definition: builtins.h:91
Definition: c.h:487
#define PG_RETURN_NULL()
Definition: fmgr.h:305