PostgreSQL Source Code git master
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 *, size_t, Oid))
 
bool searchstoplist (StopList *s, char *key)
 

Macro Definition Documentation

◆ TSL_ADDPOS

#define TSL_ADDPOS   0x01

Definition at line 142 of file ts_public.h.

◆ TSL_FILTER

#define TSL_FILTER   0x04

Definition at line 144 of file ts_public.h.

◆ TSL_PREFIX

#define TSL_PREFIX   0x02

Definition at line 143 of file ts_public.h.

Function Documentation

◆ get_tsearch_config_filename()

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

Definition at line 34 of file ts_utils.c.

36{
37 char sharepath[MAXPGPATH];
38 char *result;
39
40 /*
41 * We limit the basename to contain a-z, 0-9, and underscores. This may
42 * be overly restrictive, but we don't want to allow access to anything
43 * outside the tsearch_data directory, so for instance '/' *must* be
44 * rejected, and on some platforms '\' and ':' are risky as well. Allowing
45 * uppercase might result in incompatible behavior between case-sensitive
46 * and case-insensitive filesystems, and non-ASCII characters create other
47 * interesting risks, so on the whole a tight policy seems best.
48 */
49 if (strspn(basename, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(basename))
51 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
52 errmsg("invalid text search configuration file name \"%s\"",
53 basename)));
54
55 get_share_path(my_exec_path, sharepath);
56 result = palloc(MAXPGPATH);
57 snprintf(result, MAXPGPATH, "%s/tsearch_data/%s.%s",
58 sharepath, basename, extension);
59
60 return result;
61}
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
char my_exec_path[MAXPGPATH]
Definition: globals.c:80
void * palloc(Size size)
Definition: mcxt.c:1317
#define MAXPGPATH
void get_share_path(const char *my_exec_path, char *ret_path)
Definition: path.c:825
#define snprintf
Definition: port.h:238

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().

◆ readstoplist()

void readstoplist ( const char *  fname,
StopList s,
char *(*)(const char *, size_t, Oid wordop 
)

Definition at line 69 of file ts_utils.c.

70{
71 char **stop = NULL;
72
73 s->len = 0;
74 if (fname && *fname)
75 {
76 char *filename = get_tsearch_config_filename(fname, "stop");
78 char *line;
79 int reallen = 0;
80
83 (errcode(ERRCODE_CONFIG_FILE_ERROR),
84 errmsg("could not open stop-word file \"%s\": %m",
85 filename)));
86
87 while ((line = tsearch_readline(&trst)) != NULL)
88 {
89 char *pbuf = line;
90
91 /* Trim trailing space */
92 while (*pbuf && !isspace((unsigned char) *pbuf))
93 pbuf += pg_mblen(pbuf);
94 *pbuf = '\0';
95
96 /* Skip empty lines */
97 if (*line == '\0')
98 {
99 pfree(line);
100 continue;
101 }
102
103 if (s->len >= reallen)
104 {
105 if (reallen == 0)
106 {
107 reallen = 64;
108 stop = (char **) palloc(sizeof(char *) * reallen);
109 }
110 else
111 {
112 reallen *= 2;
113 stop = (char **) repalloc(stop, sizeof(char *) * reallen);
114 }
115 }
116
117 if (wordop)
118 {
119 stop[s->len] = wordop(line, strlen(line), DEFAULT_COLLATION_OID);
120 if (stop[s->len] != line)
121 pfree(line);
122 }
123 else
124 stop[s->len] = line;
125
126 (s->len)++;
127 }
128
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}
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1541
void pfree(void *pointer)
Definition: mcxt.c:1521
static char * filename
Definition: pg_dumpall.c:119
int pg_qsort_strcmp(const void *a, const void *b)
Definition: qsort.c:19
#define qsort(a, b, c, d)
Definition: port.h:474
int len
Definition: ts_public.h:102
char ** stop
Definition: ts_public.h:103
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
Definition: ts_locale.c:89
char * tsearch_readline(tsearch_readline_state *stp)
Definition: ts_locale.c:112
void tsearch_readline_end(tsearch_readline_state *stp)
Definition: ts_locale.c:157
char * get_tsearch_config_filename(const char *basename, const char *extension)
Definition: ts_utils.c:34

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

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

◆ searchstoplist()

bool searchstoplist ( StopList s,
char *  key 
)

Definition at line 141 of file ts_utils.c.

142{
143 return (s->stop && s->len > 0 &&
144 bsearch(&key, s->stop, s->len,
145 sizeof(char *), pg_qsort_strcmp));
146}

References sort-test::key, StopList::len, pg_qsort_strcmp(), and StopList::stop.

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