diff options
Diffstat (limited to 'src/backend/tsearch/dict_synonym.c')
-rw-r--r-- | src/backend/tsearch/dict_synonym.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/backend/tsearch/dict_synonym.c b/src/backend/tsearch/dict_synonym.c index a9d094880de..13ecfd0eed2 100644 --- a/src/backend/tsearch/dict_synonym.c +++ b/src/backend/tsearch/dict_synonym.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.10 2009/01/01 17:23:48 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/dict_synonym.c,v 1.11 2009/08/14 14:53:20 teodor Exp $ * *------------------------------------------------------------------------- */ @@ -23,6 +23,8 @@ typedef struct { char *in; char *out; + int outlen; + uint16 flags; } Syn; typedef struct @@ -36,11 +38,14 @@ typedef struct * Finds the next whitespace-delimited word within the 'in' string. * Returns a pointer to the first character of the word, and a pointer * to the next byte after the last character in the word (in *end). + * Character '*' at the end of word will not be threated as word + * charater if flags is not null. */ static char * -findwrd(char *in, char **end) +findwrd(char *in, char **end, uint16 *flags) { char *start; + char *lastchar; /* Skip leading spaces */ while (*in && t_isspace(in)) @@ -53,13 +58,27 @@ findwrd(char *in, char **end) return NULL; } - start = in; + lastchar = start = in; /* Find end of word */ while (*in && !t_isspace(in)) + { + lastchar = in; in += pg_mblen(in); + } + + if ( in - lastchar == 1 && t_iseq(lastchar, '*') && flags ) + { + *flags = TSL_PREFIX; + *end = lastchar; + } + else + { + if (flags) + *flags = 0; + *end = in; + } - *end = in; return start; } @@ -84,6 +103,7 @@ dsynonym_init(PG_FUNCTION_ARGS) *end = NULL; int cur = 0; char *line = NULL; + uint16 flags = 0; foreach(l, dictoptions) { @@ -117,7 +137,7 @@ dsynonym_init(PG_FUNCTION_ARGS) while ((line = tsearch_readline(&trst)) != NULL) { - starti = findwrd(line, &end); + starti = findwrd(line, &end, NULL); if (!starti) { /* Empty line */ @@ -130,7 +150,7 @@ dsynonym_init(PG_FUNCTION_ARGS) } *end = '\0'; - starto = findwrd(end + 1, &end); + starto = findwrd(end + 1, &end, &flags); if (!starto) { /* A line with only one word (+whitespace). Ignore silently. */ @@ -168,6 +188,9 @@ dsynonym_init(PG_FUNCTION_ARGS) d->syn[cur].out = lowerstr(starto); } + d->syn[cur].outlen = strlen(starto); + d->syn[cur].flags = flags; + cur++; skipline: @@ -212,7 +235,8 @@ dsynonym_lexize(PG_FUNCTION_ARGS) PG_RETURN_POINTER(NULL); res = palloc0(sizeof(TSLexeme) * 2); - res[0].lexeme = pstrdup(found->out); + res[0].lexeme = pnstrdup(found->out, found->outlen); + res[0].flags = found->flags; PG_RETURN_POINTER(res); } |