Age Owner TLA Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * dict.c
4 : * Standard interface to dictionary
5 : *
6 : * Portions Copyright (c) 1996-2023, 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/array.h"
20 : #include "utils/builtins.h"
21 :
22 :
23 : /*
24 : * Lexize one word by dictionary, mostly debug function
25 : */
26 : Datum
5651 tgl 27 GIC 466 : ts_lexize(PG_FUNCTION_ARGS)
5710 tgl 28 ECB : {
5651 tgl 29 GIC 466 : Oid dictId = PG_GETARG_OID(0);
2219 noah 30 CBC 466 : text *in = PG_GETARG_TEXT_PP(1);
5651 tgl 31 ECB : ArrayType *a;
32 : TSDictionaryCacheEntry *dict;
33 : TSLexeme *res,
34 : *ptr;
35 : Datum *da;
5710 tgl 36 GIC 466 : DictSubState dstate = {false, false, NULL};
5710 tgl 37 ECB :
5710 tgl 38 GIC 466 : dict = lookup_ts_dictionary_cache(dictId);
5710 tgl 39 ECB :
5710 tgl 40 GIC 466 : res = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
2118 tgl 41 ECB : PointerGetDatum(dict->dictData),
42 : PointerGetDatum(VARDATA_ANY(in)),
43 : Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
44 : PointerGetDatum(&dstate)));
45 :
5710 tgl 46 GIC 466 : if (dstate.getnext)
5710 tgl 47 ECB : {
5710 tgl 48 GIC 3 : dstate.isend = true;
5710 tgl 49 CBC 3 : ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
2118 tgl 50 ECB : PointerGetDatum(dict->dictData),
51 : PointerGetDatum(VARDATA_ANY(in)),
52 : Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
53 : PointerGetDatum(&dstate)));
5710 tgl 54 GIC 3 : if (ptr != NULL)
5710 tgl 55 LBC 0 : res = ptr;
5710 tgl 56 EUB : }
57 :
5710 tgl 58 GIC 466 : if (!res)
5651 tgl 59 CBC 28 : PG_RETURN_NULL();
5710 tgl 60 ECB :
5710 tgl 61 GIC 438 : ptr = res;
5710 tgl 62 CBC 1040 : while (ptr->lexeme)
63 602 : ptr++;
5651 64 438 : da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
5710 65 438 : ptr = res;
66 1040 : while (ptr->lexeme)
5710 tgl 67 ECB : {
5493 tgl 68 GIC 602 : da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
5710 tgl 69 CBC 602 : ptr++;
5710 tgl 70 ECB : }
71 :
282 peter 72 GNC 438 : a = construct_array_builtin(da, ptr - res, TEXTOID);
5710 tgl 73 ECB :
5710 tgl 74 CBC 438 : ptr = res;
75 1040 : while (ptr->lexeme)
76 : {
77 602 : pfree(DatumGetPointer(da[ptr - res]));
78 602 : pfree(ptr->lexeme);
5710 tgl 79 GIC 602 : ptr++;
5710 tgl 80 ECB : }
5710 tgl 81 GIC 438 : pfree(res);
82 438 : pfree(da);
83 :
5651 84 438 : PG_RETURN_POINTER(a);
85 : }
|