PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ts_public.h File Reference
#include "tsearch/ts_type.h"
Include dependency graph for ts_public.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LexDescr
 
struct  HeadlineWordEntry
 
struct  HeadlineParsedText
 
struct  StopList
 
struct  TSLexeme
 
struct  DictSubState
 

Macros

#define TSL_ADDPOS   0x01
 
#define TSL_PREFIX   0x02
 
#define TSL_FILTER   0x04
 

Functions

char * get_tsearch_config_filename (const char *basename, const char *extension)
 
void readstoplist (const char *fname, StopList *s, char *(*wordop)(const char *))
 
bool searchstoplist (StopList *s, char *key)
 

Macro Definition Documentation

#define TSL_ADDPOS   0x01

Definition at line 115 of file ts_public.h.

Referenced by addHLParsedLex(), compileTheSubstitute(), and parsetext().

#define TSL_FILTER   0x04

Definition at line 117 of file ts_public.h.

Referenced by LexizeExec(), and unaccent_lexize().

#define TSL_PREFIX   0x02

Definition at line 116 of file ts_public.h.

Referenced by findwrd(), parsetext(), and pushval_morph().

Function Documentation

char* get_tsearch_config_filename ( const char *  basename,
const char *  extension 
)

Definition at line 33 of file ts_utils.c.

References ereport, errcode(), errmsg(), ERROR, get_share_path(), MAXPGPATH, my_exec_path, palloc(), and snprintf().

Referenced by dispell_init(), dsynonym_init(), initTrie(), read_dictionary(), readstoplist(), and thesaurusRead().

35 {
36  char sharepath[MAXPGPATH];
37  char *result;
38 
39  /*
40  * We limit the basename to contain a-z, 0-9, and underscores. This may
41  * be overly restrictive, but we don't want to allow access to anything
42  * outside the tsearch_data directory, so for instance '/' *must* be
43  * rejected, and on some platforms '\' and ':' are risky as well. Allowing
44  * uppercase might result in incompatible behavior between case-sensitive
45  * and case-insensitive filesystems, and non-ASCII characters create other
46  * interesting risks, so on the whole a tight policy seems best.
47  */
48  if (strspn(basename, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(basename))
49  ereport(ERROR,
50  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
51  errmsg("invalid text search configuration file name \"%s\"",
52  basename)));
53 
54  get_share_path(my_exec_path, sharepath);
55  result = palloc(MAXPGPATH);
56  snprintf(result, MAXPGPATH, "%s/tsearch_data/%s.%s",
57  sharepath, basename, extension);
58 
59  return result;
60 }
int errcode(int sqlerrcode)
Definition: elog.c:575
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
#define ereport(elevel, rest)
Definition: elog.h:122
char my_exec_path[MAXPGPATH]
Definition: globals.c:63
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
void get_share_path(const char *my_exec_path, char *ret_path)
Definition: path.c:704
void readstoplist ( const char *  fname,
StopList s,
char *(*)(const char *)  wordop 
)

Definition at line 68 of file ts_utils.c.

References ereport, errcode(), errmsg(), ERROR, filename, get_tsearch_config_filename(), StopList::len, NULL, palloc(), pfree(), pg_mblen(), pg_qsort_strcmp(), qsort, repalloc(), StopList::stop, t_isspace, tsearch_readline(), tsearch_readline_begin(), and tsearch_readline_end().

Referenced by dispell_init(), dsimple_init(), and dsnowball_init().

69 {
70  char **stop = NULL;
71 
72  s->len = 0;
73  if (fname && *fname)
74  {
75  char *filename = get_tsearch_config_filename(fname, "stop");
77  char *line;
78  int reallen = 0;
79 
80  if (!tsearch_readline_begin(&trst, filename))
81  ereport(ERROR,
82  (errcode(ERRCODE_CONFIG_FILE_ERROR),
83  errmsg("could not open stop-word file \"%s\": %m",
84  filename)));
85 
86  while ((line = tsearch_readline(&trst)) != NULL)
87  {
88  char *pbuf = line;
89 
90  /* Trim trailing space */
91  while (*pbuf && !t_isspace(pbuf))
92  pbuf += pg_mblen(pbuf);
93  *pbuf = '\0';
94 
95  /* Skip empty lines */
96  if (*line == '\0')
97  {
98  pfree(line);
99  continue;
100  }
101 
102  if (s->len >= reallen)
103  {
104  if (reallen == 0)
105  {
106  reallen = 64;
107  stop = (char **) palloc(sizeof(char *) * reallen);
108  }
109  else
110  {
111  reallen *= 2;
112  stop = (char **) repalloc((void *) stop,
113  sizeof(char *) * reallen);
114  }
115  }
116 
117  if (wordop)
118  {
119  stop[s->len] = wordop(line);
120  if (stop[s->len] != line)
121  pfree(line);
122  }
123  else
124  stop[s->len] = line;
125 
126  (s->len)++;
127  }
128 
129  tsearch_readline_end(&trst);
130  pfree(filename);
131  }
132 
133  s->stop = stop;
134 
135  /* Sort to allow binary searching */
136  if (s->stop && s->len > 0)
137  qsort(s->stop, s->len, sizeof(char *), pg_qsort_strcmp);
138 }
#define t_isspace(x)
Definition: ts_locale.h:58
int errcode(int sqlerrcode)
Definition: elog.c:575
void pfree(void *pointer)
Definition: mcxt.c:992
char ** stop
Definition: ts_public.h:76
#define ERROR
Definition: elog.h:43
char * get_tsearch_config_filename(const char *basename, const char *extension)
Definition: ts_utils.c:33
#define ereport(elevel, rest)
Definition: elog.h:122
int len
Definition: ts_public.h:75
#define NULL
Definition: c.h:226
int pg_qsort_strcmp(const void *a, const void *b)
Definition: qsort.c:232
int pg_mblen(const char *mbstr)
Definition: mbutils.c:771
void tsearch_readline_end(tsearch_readline_state *stp)
Definition: ts_locale.c:153
char * tsearch_readline(tsearch_readline_state *stp)
Definition: ts_locale.c:138
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1021
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
Definition: ts_locale.c:116
static char * filename
Definition: pg_dumpall.c:84
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define qsort(a, b, c, d)
Definition: port.h:440
bool searchstoplist ( StopList s,
char *  key 
)

Definition at line 141 of file ts_utils.c.

References StopList::len, pg_qsort_strcmp(), and StopList::stop.

Referenced by dispell_lexize(), dsimple_lexize(), and dsnowball_lexize().

142 {
143  return (s->stop && s->len > 0 &&
144  bsearch(&key, s->stop, s->len,
145  sizeof(char *), pg_qsort_strcmp)) ? true : false;
146 }
char ** stop
Definition: ts_public.h:76
int len
Definition: ts_public.h:75
int pg_qsort_strcmp(const void *a, const void *b)
Definition: qsort.c:232