PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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{
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)
50 errmsg("multiple StopWords parameters")));
52 stoploaded = true;
53 }
54 else if (strcmp(defel->defname, "accept") == 0)
55 {
56 if (acceptloaded)
59 errmsg("multiple Accept parameters")));
61 acceptloaded = true;
62 }
63 else
64 {
67 errmsg("unrecognized simple dictionary parameter: \"%s\"",
68 defel->defname)));
69 }
70 }
71
73}
char * defGetString(DefElem *def)
Definition define.c:34
bool defGetBoolean(DefElem *def)
Definition define.c:93
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define palloc0_object(type)
Definition fe_memutils.h:75
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
#define lfirst(lc)
Definition pg_list.h:172
static int fb(int x)
StopList stoplist
Definition dict_simple.c:25
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(), ereport, errcode(), errmsg(), ERROR, fb(), lfirst, palloc0_object, 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;
82 TSLexeme *res;
83
85
86 if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
87 {
88 /* reject as stopword */
89 pfree(txt);
90 res = palloc0_array(TSLexeme, 2);
92 }
93 else if (d->accept)
94 {
95 /* accept */
96 res = palloc0_array(TSLexeme, 2);
97 res[0].lexeme = txt;
99 }
100 else
101 {
102 /* report as unrecognized */
103 pfree(txt);
105 }
106}
int32_t int32
Definition c.h:542
#define palloc0_array(type, count)
Definition fe_memutils.h:77
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
void pfree(void *pointer)
Definition mcxt.c:1616
const void size_t len
char * lexeme
Definition ts_public.h:138
bool searchstoplist(StopList *s, char *key)
Definition ts_utils.c:141

References DictSimple::accept, fb(), len, TSLexeme::lexeme, palloc0_array, pfree(), PG_GETARG_INT32, PG_GETARG_POINTER, PG_RETURN_POINTER, searchstoplist(), DictSimple::stoplist, and str_tolower().