PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dict.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dict.c
4  * Standard interface to dictionary
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  *
8  *
9  * IDENTIFICATION
10  * src/backend/tsearch/dict.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include "catalog/pg_type.h"
17 #include "tsearch/ts_cache.h"
18 #include "tsearch/ts_utils.h"
19 #include "utils/builtins.h"
20 
21 
22 /*
23  * Lexize one word by dictionary, mostly debug function
24  */
25 Datum
27 {
28  Oid dictId = PG_GETARG_OID(0);
29  text *in = PG_GETARG_TEXT_P(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:305
#define VARDATA(PTR)
Definition: postgres.h:305
#define TEXTOID
Definition: pg_type.h:324
#define VARSIZE(PTR)
Definition: postgres.h:306
#define PointerGetDatum(X)
Definition: postgres.h:564
#define VARHDRSZ
Definition: c.h:440
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:3306
unsigned int Oid
Definition: postgres_ext.h:31
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
Definition: ts_cache.c:210
void pfree(void *pointer)
Definition: mcxt.c:992
char * lexeme
Definition: ts_public.h:111
#define PG_GETARG_OID(n)
Definition: fmgr.h:231
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
Definition: fmgr.h:579
uintptr_t Datum
Definition: postgres.h:374
#define NULL
Definition: c.h:226
#define DatumGetPointer(X)
Definition: postgres.h:557
Datum ts_lexize(PG_FUNCTION_ARGS)
Definition: dict.c:26
#define Int32GetDatum(X)
Definition: postgres.h:487
void * palloc(Size size)
Definition: mcxt.c:891
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:269
#define CStringGetTextDatum(s)
Definition: builtins.h:90
Definition: c.h:434
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
#define PG_RETURN_NULL()
Definition: fmgr.h:289