PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
dict_simple.c File Reference
#include "postgres.h"
#include "catalog/pg_collation_d.h"
#include "commands/defrem.h"
#include "tsearch/ts_public.h"
#include "utils/fmgrprotos.h"
#include "utils/formatting.h"
Include dependency graph for dict_simple.c:

Go to the source code of this file.

Data Structures

struct  DictSimple
 

Functions

Datum dsimple_init (PG_FUNCTION_ARGS)
 
Datum dsimple_lexize (PG_FUNCTION_ARGS)
 

Function Documentation

◆ dsimple_init()

Datum dsimple_init ( PG_FUNCTION_ARGS  )

Definition at line 31 of file dict_simple.c.

32{
33 List *dictoptions = (List *) PG_GETARG_POINTER(0);
34 DictSimple *d = (DictSimple *) palloc0(sizeof(DictSimple));
35 bool stoploaded = false,
36 acceptloaded = false;
37 ListCell *l;
38
39 d->accept = true; /* default */
40
41 foreach(l, dictoptions)
42 {
43 DefElem *defel = (DefElem *) lfirst(l);
44
45 if (strcmp(defel->defname, "stopwords") == 0)
46 {
47 if (stoploaded)
49 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
50 errmsg("multiple StopWords parameters")));
52 stoploaded = true;
53 }
54 else if (strcmp(defel->defname, "accept") == 0)
55 {
56 if (acceptloaded)
58 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
59 errmsg("multiple Accept parameters")));
60 d->accept = defGetBoolean(defel);
61 acceptloaded = true;
62 }
63 else
64 {
66 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
67 errmsg("unrecognized simple dictionary parameter: \"%s\"",
68 defel->defname)));
69 }
70 }
71
73}
char * defGetString(DefElem *def)
Definition: define.c:35
bool defGetBoolean(DefElem *def)
Definition: define.c:94
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1591
void * palloc0(Size size)
Definition: mcxt.c:1347
#define lfirst(lc)
Definition: pg_list.h:172
char * defname
Definition: parsenodes.h:817
StopList stoplist
Definition: dict_simple.c:25
bool accept
Definition: dict_simple.c:26
Definition: pg_list.h:54
void readstoplist(const char *fname, StopList *s, char *(*wordop)(const char *, size_t, Oid))
Definition: ts_utils.c:69

References DictSimple::accept, defGetBoolean(), defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, lfirst, palloc0(), PG_GETARG_POINTER, PG_RETURN_POINTER, readstoplist(), DictSimple::stoplist, and str_tolower().

◆ dsimple_lexize()

Datum dsimple_lexize ( PG_FUNCTION_ARGS  )

Definition at line 76 of file dict_simple.c.

77{
79 char *in = (char *) PG_GETARG_POINTER(1);
81 char *txt;
83
84 txt = str_tolower(in, len, DEFAULT_COLLATION_OID);
85
86 if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
87 {
88 /* reject as stopword */
89 pfree(txt);
90 res = palloc0(sizeof(TSLexeme) * 2);
92 }
93 else if (d->accept)
94 {
95 /* accept */
96 res = palloc0(sizeof(TSLexeme) * 2);
97 res[0].lexeme = txt;
99 }
100 else
101 {
102 /* report as unrecognized */
103 pfree(txt);
104 PG_RETURN_POINTER(NULL);
105 }
106}
int32_t int32
Definition: c.h:481
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void pfree(void *pointer)
Definition: mcxt.c:1521
const void size_t len
bool searchstoplist(StopList *s, char *key)
Definition: ts_utils.c:141

References DictSimple::accept, len, palloc0(), pfree(), PG_GETARG_INT32, PG_GETARG_POINTER, PG_RETURN_POINTER, res, searchstoplist(), DictSimple::stoplist, and str_tolower().