PostgreSQL Source Code
git master
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-2024, 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_public.h
"
19
#include "
utils/array.h
"
20
#include "
utils/builtins.h
"
21
22
23
/*
24
* Lexize one word by dictionary, mostly debug function
25
*/
26
Datum
27
ts_lexize
(
PG_FUNCTION_ARGS
)
28
{
29
Oid
dictId =
PG_GETARG_OID
(0);
30
text
*in =
PG_GETARG_TEXT_PP
(1);
31
ArrayType
*
a
;
32
TSDictionaryCacheEntry
*dict;
33
TSLexeme
*
res
,
34
*ptr;
35
Datum
*da;
36
DictSubState
dstate = {
false
,
false
, NULL};
37
38
dict =
lookup_ts_dictionary_cache
(dictId);
39
40
res
= (
TSLexeme
*)
DatumGetPointer
(
FunctionCall4
(&dict->
lexize
,
41
PointerGetDatum
(dict->
dictData
),
42
PointerGetDatum
(
VARDATA_ANY
(in)),
43
Int32GetDatum
(
VARSIZE_ANY_EXHDR
(in)),
44
PointerGetDatum
(&dstate)));
45
46
if
(dstate.
getnext
)
47
{
48
dstate.
isend
=
true
;
49
ptr = (
TSLexeme
*)
DatumGetPointer
(
FunctionCall4
(&dict->
lexize
,
50
PointerGetDatum
(dict->
dictData
),
51
PointerGetDatum
(
VARDATA_ANY
(in)),
52
Int32GetDatum
(
VARSIZE_ANY_EXHDR
(in)),
53
PointerGetDatum
(&dstate)));
54
if
(ptr != NULL)
55
res
= ptr;
56
}
57
58
if
(!
res
)
59
PG_RETURN_NULL
();
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
84
PG_RETURN_POINTER
(
a
);
85
}
array.h
construct_array_builtin
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition:
arrayfuncs.c:3381
builtins.h
CStringGetTextDatum
#define CStringGetTextDatum(s)
Definition:
builtins.h:97
res
static void PGresult * res
Definition:
dblink.c:165
ts_lexize
Datum ts_lexize(PG_FUNCTION_ARGS)
Definition:
dict.c:27
PG_GETARG_OID
#define PG_GETARG_OID(n)
Definition:
fmgr.h:275
PG_GETARG_TEXT_PP
#define PG_GETARG_TEXT_PP(n)
Definition:
fmgr.h:309
PG_RETURN_NULL
#define PG_RETURN_NULL()
Definition:
fmgr.h:345
FunctionCall4
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
Definition:
fmgr.h:665
PG_RETURN_POINTER
#define PG_RETURN_POINTER(x)
Definition:
fmgr.h:361
PG_FUNCTION_ARGS
#define PG_FUNCTION_ARGS
Definition:
fmgr.h:193
a
int a
Definition:
isn.c:69
pfree
void pfree(void *pointer)
Definition:
mcxt.c:1521
palloc
void * palloc(Size size)
Definition:
mcxt.c:1317
pg_type.h
postgres.h
PointerGetDatum
static Datum PointerGetDatum(const void *X)
Definition:
postgres.h:322
Datum
uintptr_t Datum
Definition:
postgres.h:64
DatumGetPointer
static Pointer DatumGetPointer(Datum X)
Definition:
postgres.h:312
Int32GetDatum
static Datum Int32GetDatum(int32 X)
Definition:
postgres.h:212
Oid
unsigned int Oid
Definition:
postgres_ext.h:31
ArrayType
Definition:
array.h:93
DictSubState
Definition:
ts_public.h:151
DictSubState::isend
bool isend
Definition:
ts_public.h:152
DictSubState::getnext
bool getnext
Definition:
ts_public.h:154
TSDictionaryCacheEntry
Definition:
ts_cache.h:52
TSDictionaryCacheEntry::dictData
void * dictData
Definition:
ts_cache.h:62
TSDictionaryCacheEntry::lexize
FmgrInfo lexize
Definition:
ts_cache.h:59
TSLexeme
Definition:
ts_public.h:116
TSLexeme::lexeme
char * lexeme
Definition:
ts_public.h:138
varlena
Definition:
c.h:690
lookup_ts_dictionary_cache
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
Definition:
ts_cache.c:208
ts_cache.h
ts_public.h
VARDATA_ANY
#define VARDATA_ANY(PTR)
Definition:
varatt.h:324
VARSIZE_ANY_EXHDR
#define VARSIZE_ANY_EXHDR(PTR)
Definition:
varatt.h:317
src
backend
tsearch
dict.c
Generated on Mon Oct 7 2024 00:13:21 for PostgreSQL Source Code by
1.9.1