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_public.h"
#include "utils/array.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 27 of file dict.c.

28 {
29  Oid dictId = PG_GETARG_OID(0);
30  text *in = PG_GETARG_TEXT_PP(1);
31  ArrayType *a;
33  TSLexeme *res,
34  *ptr;
35  Datum *da;
36  DictSubState dstate = {false, false, NULL};
37 
38  dict = lookup_ts_dictionary_cache(dictId);
39 
44  PointerGetDatum(&dstate)));
45 
46  if (dstate.getnext)
47  {
48  dstate.isend = true;
53  PointerGetDatum(&dstate)));
54  if (ptr != NULL)
55  res = ptr;
56  }
57 
58  if (!res)
60 
61  ptr = res;
62  while (ptr->lexeme)
63  ptr++;
64  da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
65  ptr = res;
66  while (ptr->lexeme)
67  {
68  da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
69  ptr++;
70  }
71 
72  a = construct_array_builtin(da, ptr - res, TEXTOID);
73 
74  ptr = res;
75  while (ptr->lexeme)
76  {
77  pfree(DatumGetPointer(da[ptr - res]));
78  pfree(ptr->lexeme);
79  ptr++;
80  }
81  pfree(res);
82  pfree(da);
83 
85 }
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3374
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
Definition: fmgr.h:666
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int a
Definition: isn.c:69
void pfree(void *pointer)
Definition: mcxt.c:1520
void * palloc(Size size)
Definition: mcxt.c:1316
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
unsigned int Oid
Definition: postgres_ext.h:31
bool getnext
Definition: ts_public.h:154
char * lexeme
Definition: ts_public.h:138
Definition: c.h:687
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
Definition: ts_cache.c:208
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

References a, construct_array_builtin(), 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(), res, VARDATA_ANY, and VARSIZE_ANY_EXHDR.