PostgreSQL Source Code  git master
dict_simple.c File Reference
#include "postgres.h"
#include "commands/defrem.h"
#include "tsearch/ts_locale.h"
#include "tsearch/ts_public.h"
#include "utils/fmgrprotos.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 30 of file dict_simple.c.

31 {
32  List *dictoptions = (List *) PG_GETARG_POINTER(0);
33  DictSimple *d = (DictSimple *) palloc0(sizeof(DictSimple));
34  bool stoploaded = false,
35  acceptloaded = false;
36  ListCell *l;
37 
38  d->accept = true; /* default */
39 
40  foreach(l, dictoptions)
41  {
42  DefElem *defel = (DefElem *) lfirst(l);
43 
44  if (strcmp(defel->defname, "stopwords") == 0)
45  {
46  if (stoploaded)
47  ereport(ERROR,
48  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
49  errmsg("multiple StopWords parameters")));
51  stoploaded = true;
52  }
53  else if (strcmp(defel->defname, "accept") == 0)
54  {
55  if (acceptloaded)
56  ereport(ERROR,
57  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
58  errmsg("multiple Accept parameters")));
59  d->accept = defGetBoolean(defel);
60  acceptloaded = true;
61  }
62  else
63  {
64  ereport(ERROR,
65  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
66  errmsg("unrecognized simple dictionary parameter: \"%s\"",
67  defel->defname)));
68  }
69  }
70 
72 }
bool defGetBoolean(DefElem *def)
Definition: define.c:107
char * defGetString(DefElem *def)
Definition: define.c:48
int errcode(int sqlerrcode)
Definition: elog.c:857
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
void * palloc0(Size size)
Definition: mcxt.c:1346
#define lfirst(lc)
Definition: pg_list.h:172
char * defname
Definition: parsenodes.h:815
StopList stoplist
Definition: dict_simple.c:24
bool accept
Definition: dict_simple.c:25
Definition: pg_list.h:54
char * lowerstr(const char *str)
Definition: ts_locale.c:253
void readstoplist(const char *fname, StopList *s, char *(*wordop)(const char *))
Definition: ts_utils.c:68

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

◆ dsimple_lexize()

Datum dsimple_lexize ( PG_FUNCTION_ARGS  )

Definition at line 75 of file dict_simple.c.

76 {
78  char *in = (char *) PG_GETARG_POINTER(1);
80  char *txt;
81  TSLexeme *res;
82 
83  txt = lowerstr_with_len(in, len);
84 
85  if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
86  {
87  /* reject as stopword */
88  pfree(txt);
89  res = palloc0(sizeof(TSLexeme) * 2);
91  }
92  else if (d->accept)
93  {
94  /* accept */
95  res = palloc0(sizeof(TSLexeme) * 2);
96  res[0].lexeme = txt;
98  }
99  else
100  {
101  /* report as unrecognized */
102  pfree(txt);
103  PG_RETURN_POINTER(NULL);
104  }
105 }
signed int int32
Definition: c.h:494
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void pfree(void *pointer)
Definition: mcxt.c:1520
const void size_t len
char * lowerstr_with_len(const char *str, int len)
Definition: ts_locale.c:266
bool searchstoplist(StopList *s, char *key)
Definition: ts_utils.c:140

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