PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dict_simple.c File Reference
#include "postgres.h"
#include "commands/defrem.h"
#include "tsearch/ts_locale.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.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

Datum dsimple_init ( PG_FUNCTION_ARGS  )

Definition at line 30 of file dict_simple.c.

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

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 (pg_strcasecmp("StopWords", defel->defname) == 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 (pg_strcasecmp("Accept", defel->defname) == 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 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
char * lowerstr(const char *str)
Definition: ts_locale.c:228
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
bool defGetBoolean(DefElem *def)
Definition: define.c:111
bool accept
Definition: dict_simple.c:25
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
#define ereport(elevel, rest)
Definition: elog.h:122
StopList stoplist
Definition: dict_simple.c:24
void readstoplist(const char *fname, StopList *s, char *(*wordop)(const char *))
Definition: ts_utils.c:68
void * palloc0(Size size)
Definition: mcxt.c:877
#define lfirst(lc)
Definition: pg_list.h:106
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:719
Definition: pg_list.h:45
Datum dsimple_lexize ( PG_FUNCTION_ARGS  )

Definition at line 75 of file dict_simple.c.

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

76 {
78  char *in = (char *) PG_GETARG_POINTER(1);
79  int32 len = PG_GETARG_INT32(2);
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);
90  PG_RETURN_POINTER(res);
91  }
92  else if (d->accept)
93  {
94  /* accept */
95  res = palloc0(sizeof(TSLexeme) * 2);
96  res[0].lexeme = txt;
97  PG_RETURN_POINTER(res);
98  }
99  else
100  {
101  /* report as unrecognized */
102  pfree(txt);
103  PG_RETURN_POINTER(NULL);
104  }
105 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
char * lowerstr_with_len(const char *str, int len)
Definition: ts_locale.c:241
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
signed int int32
Definition: c.h:246
void pfree(void *pointer)
Definition: mcxt.c:949
bool accept
Definition: dict_simple.c:25
char * lexeme
Definition: ts_public.h:111
StopList stoplist
Definition: dict_simple.c:24
void * palloc0(Size size)
Definition: mcxt.c:877
bool searchstoplist(StopList *s, char *key)
Definition: ts_utils.c:141