7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.10 2009/01/01 17:23:48 momjian Exp $
10
+ * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.11 2009/08/14 14:53:20 teodor Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -23,6 +23,8 @@ typedef struct
23
23
{
24
24
char * in ;
25
25
char * out ;
26
+ int outlen ;
27
+ uint16 flags ;
26
28
} Syn ;
27
29
28
30
typedef struct
@@ -36,11 +38,14 @@ typedef struct
36
38
* Finds the next whitespace-delimited word within the 'in' string.
37
39
* Returns a pointer to the first character of the word, and a pointer
38
40
* to the next byte after the last character in the word (in *end).
41
+ * Character '*' at the end of word will not be threated as word
42
+ * charater if flags is not null.
39
43
*/
40
44
static char *
41
- findwrd (char * in , char * * end )
45
+ findwrd (char * in , char * * end , uint16 * flags )
42
46
{
43
47
char * start ;
48
+ char * lastchar ;
44
49
45
50
/* Skip leading spaces */
46
51
while (* in && t_isspace (in ))
@@ -53,13 +58,27 @@ findwrd(char *in, char **end)
53
58
return NULL ;
54
59
}
55
60
56
- start = in ;
61
+ lastchar = start = in ;
57
62
58
63
/* Find end of word */
59
64
while (* in && !t_isspace (in ))
65
+ {
66
+ lastchar = in ;
60
67
in += pg_mblen (in );
68
+ }
69
+
70
+ if ( in - lastchar == 1 && t_iseq (lastchar , '*' ) && flags )
71
+ {
72
+ * flags = TSL_PREFIX ;
73
+ * end = lastchar ;
74
+ }
75
+ else
76
+ {
77
+ if (flags )
78
+ * flags = 0 ;
79
+ * end = in ;
80
+ }
61
81
62
- * end = in ;
63
82
return start ;
64
83
}
65
84
@@ -84,6 +103,7 @@ dsynonym_init(PG_FUNCTION_ARGS)
84
103
* end = NULL ;
85
104
int cur = 0 ;
86
105
char * line = NULL ;
106
+ uint16 flags = 0 ;
87
107
88
108
foreach (l , dictoptions )
89
109
{
@@ -117,7 +137,7 @@ dsynonym_init(PG_FUNCTION_ARGS)
117
137
118
138
while ((line = tsearch_readline (& trst )) != NULL )
119
139
{
120
- starti = findwrd (line , & end );
140
+ starti = findwrd (line , & end , NULL );
121
141
if (!starti )
122
142
{
123
143
/* Empty line */
@@ -130,7 +150,7 @@ dsynonym_init(PG_FUNCTION_ARGS)
130
150
}
131
151
* end = '\0' ;
132
152
133
- starto = findwrd (end + 1 , & end );
153
+ starto = findwrd (end + 1 , & end , & flags );
134
154
if (!starto )
135
155
{
136
156
/* A line with only one word (+whitespace). Ignore silently. */
@@ -168,6 +188,9 @@ dsynonym_init(PG_FUNCTION_ARGS)
168
188
d -> syn [cur ].out = lowerstr (starto );
169
189
}
170
190
191
+ d -> syn [cur ].outlen = strlen (starto );
192
+ d -> syn [cur ].flags = flags ;
193
+
171
194
cur ++ ;
172
195
173
196
skipline :
@@ -212,7 +235,8 @@ dsynonym_lexize(PG_FUNCTION_ARGS)
212
235
PG_RETURN_POINTER (NULL );
213
236
214
237
res = palloc0 (sizeof (TSLexeme ) * 2 );
215
- res [0 ].lexeme = pstrdup (found -> out );
238
+ res [0 ].lexeme = pnstrdup (found -> out , found -> outlen );
239
+ res [0 ].flags = found -> flags ;
216
240
217
241
PG_RETURN_POINTER (res );
218
242
}
0 commit comments