Coverage Report

Created: 2025-09-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/postgres/src/backend/tsearch/dict.c
Line
Count
Source
1
/*-------------------------------------------------------------------------
2
 *
3
 * dict.c
4
 *    Standard interface to dictionary
5
 *
6
 * Portions Copyright (c) 1996-2025, 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
0
{
29
0
  Oid     dictId = PG_GETARG_OID(0);
30
0
  text     *in = PG_GETARG_TEXT_PP(1);
31
0
  ArrayType  *a;
32
0
  TSDictionaryCacheEntry *dict;
33
0
  TSLexeme   *res,
34
0
         *ptr;
35
0
  Datum    *da;
36
0
  DictSubState dstate = {false, false, NULL};
37
38
0
  dict = lookup_ts_dictionary_cache(dictId);
39
40
0
  res = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
41
0
                           PointerGetDatum(dict->dictData),
42
0
                           PointerGetDatum(VARDATA_ANY(in)),
43
0
                           Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
44
0
                           PointerGetDatum(&dstate)));
45
46
0
  if (dstate.getnext)
47
0
  {
48
0
    dstate.isend = true;
49
0
    ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
50
0
                             PointerGetDatum(dict->dictData),
51
0
                             PointerGetDatum(VARDATA_ANY(in)),
52
0
                             Int32GetDatum(VARSIZE_ANY_EXHDR(in)),
53
0
                             PointerGetDatum(&dstate)));
54
0
    if (ptr != NULL)
55
0
      res = ptr;
56
0
  }
57
58
0
  if (!res)
59
0
    PG_RETURN_NULL();
60
61
0
  ptr = res;
62
0
  while (ptr->lexeme)
63
0
    ptr++;
64
0
  da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
65
0
  ptr = res;
66
0
  while (ptr->lexeme)
67
0
  {
68
0
    da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
69
0
    ptr++;
70
0
  }
71
72
0
  a = construct_array_builtin(da, ptr - res, TEXTOID);
73
74
0
  ptr = res;
75
0
  while (ptr->lexeme)
76
0
  {
77
0
    pfree(DatumGetPointer(da[ptr - res]));
78
0
    pfree(ptr->lexeme);
79
0
    ptr++;
80
0
  }
81
0
  pfree(res);
82
0
  pfree(da);
83
84
0
  PG_RETURN_POINTER(a);
85
0
}