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-2022, 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
26
ts_lexize
(
PG_FUNCTION_ARGS
)
27
{
28
Oid
dictId =
PG_GETARG_OID
(0);
29
text
*in =
PG_GETARG_TEXT_PP
(1);
30
ArrayType
*
a
;
31
TSDictionaryCacheEntry
*dict;
32
TSLexeme
*
res
,
33
*ptr;
34
Datum
*da;
35
DictSubState
dstate = {
false
,
false
, NULL};
36
37
dict =
lookup_ts_dictionary_cache
(dictId);
38
39
res
= (
TSLexeme
*)
DatumGetPointer
(
FunctionCall4
(&dict->
lexize
,
40
PointerGetDatum
(dict->
dictData
),
41
PointerGetDatum
(
VARDATA_ANY
(in)),
42
Int32GetDatum
(
VARSIZE_ANY_EXHDR
(in)),
43
PointerGetDatum
(&dstate)));
44
45
if
(dstate.
getnext
)
46
{
47
dstate.
isend
=
true
;
48
ptr = (
TSLexeme
*)
DatumGetPointer
(
FunctionCall4
(&dict->
lexize
,
49
PointerGetDatum
(dict->
dictData
),
50
PointerGetDatum
(
VARDATA_ANY
(in)),
51
Int32GetDatum
(
VARSIZE_ANY_EXHDR
(in)),
52
PointerGetDatum
(&dstate)));
53
if
(ptr != NULL)
54
res
= ptr;
55
}
56
57
if
(!
res
)
58
PG_RETURN_NULL
();
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
TYPALIGN_INT);
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
88
PG_RETURN_POINTER
(
a
);
89
}
construct_array
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition:
arrayfuncs.c:3319
builtins.h
CStringGetTextDatum
#define CStringGetTextDatum(s)
Definition:
builtins.h:85
res
static void PGresult * res
Definition:
dblink.c:156
ts_lexize
Datum ts_lexize(PG_FUNCTION_ARGS)
Definition:
dict.c:26
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:655
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:1175
palloc
void * palloc(Size size)
Definition:
mcxt.c:1068
pg_type.h
postgres.h
Datum
uintptr_t Datum
Definition:
postgres.h:411
DatumGetPointer
#define DatumGetPointer(X)
Definition:
postgres.h:593
VARDATA_ANY
#define VARDATA_ANY(PTR)
Definition:
postgres.h:361
Int32GetDatum
#define Int32GetDatum(X)
Definition:
postgres.h:523
PointerGetDatum
#define PointerGetDatum(X)
Definition:
postgres.h:600
VARSIZE_ANY_EXHDR
#define VARSIZE_ANY_EXHDR(PTR)
Definition:
postgres.h:354
Oid
unsigned int Oid
Definition:
postgres_ext.h:31
ArrayType
Definition:
array.h:86
DictSubState
Definition:
ts_public.h:124
DictSubState::isend
bool isend
Definition:
ts_public.h:125
DictSubState::getnext
bool getnext
Definition:
ts_public.h:127
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:89
TSLexeme::lexeme
char * lexeme
Definition:
ts_public.h:111
varlena
Definition:
c.h:622
lookup_ts_dictionary_cache
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
Definition:
ts_cache.c:208
ts_cache.h
ts_utils.h
src
backend
tsearch
dict.c
Generated on Sat May 28 2022 06:13:19 for PostgreSQL Source Code by
1.9.1