Only in .: .svn diff -u /home/ivoras/temp/dict_regex/Makefile ./Makefile --- /home/ivoras/temp/dict_regex/Makefile 2008-02-29 20:56:13.000000000 +0100 +++ ./Makefile 2010-07-09 16:54:13.000000000 +0200 @@ -6,7 +6,8 @@ OBJS = dict_regex.o parser.o utils.o DATA_built = dict_regex.sql DOCS = README.dict_regex -SHLIB_LINK = -lpcre +SHLIB_LINK = -L/usr/local/lib -lpcre +PG_CPPFLAGS = -I/usr/local/include REGRESS = dict_regex include $(top_srcdir)/contrib/contrib-global.mk Only in .: README.build Common subdirectories: /home/ivoras/temp/dict_regex/data and ./data Common subdirectories: /home/ivoras/temp/dict_regex/expected and ./expected Common subdirectories: /home/ivoras/temp/dict_regex/input and ./input diff -u /home/ivoras/temp/dict_regex/parser.c ./parser.c --- /home/ivoras/temp/dict_regex/parser.c 2008-02-29 20:40:47.000000000 +0100 +++ ./parser.c 2010-07-09 18:43:50.000000000 +0200 @@ -9,6 +9,11 @@ #define DEBUG_MESSAGES #include "parser.h" +#include "utils.h" +#include "commands/defrem.h" +#include "fmgr.h" +#include "tsearch/ts_locale.h" +#include "tsearch/ts_utils.h" #define MAX_MATCHES 10 @@ -92,13 +97,13 @@ { int result; - /* COnstruct current string for matching */ + /* Construct current string for matching */ if(rule->string) add_to_string(&rule->string, " "); add_to_string(&rule->string, word); result = pcre_exec(rule->pattern, NULL, rule->string, strlen(rule->string), - 0, PCRE_PARTIAL, rule->ovector, MAX_MATCHES*3); + 0, 0, rule->ovector, MAX_MATCHES*3); if(result == PCRE_ERROR_PARTIAL) rule->state = PROCESSING; @@ -115,6 +120,7 @@ if(result >= 0) { rule->nmatches = result; + //elog(NOTICE, "Matching %s to %s: %d", rule->source, word, result); if(!result) dprintf("Number of matches found exceed maximum limit of %d!\n", MAX_MATCHES); @@ -217,10 +223,11 @@ void parser_read_rules(parser_str *parser, char *filename) { + char *real_filename = get_tsearch_config_filename(filename, "regex"); FILE *file = NULL; - if(file_exists_and_normal(filename)) - file = fopen(filename, "r"); + if(file_exists_and_normal(real_filename)) + file = fopen(real_filename, "r"); if(file) { @@ -252,7 +259,9 @@ } fclose(file); - } + } else + elog(ERROR, "Cannot open file: %s (errno %d)", real_filename, + errno); } void @@ -338,19 +347,27 @@ return is_matched; } -/* Returns the longest match - match with longest rule->string actually */ +/* Returns the longest match - match shortest result actually */ char * parser_match(parser_str *parser) { - char *result = NULL; + char *result = NULL, *new_result = NULL; + int result_len = 2048, new_len = 2048; int d; for(d = 0; d < parser->nrules; d++) if(parser->rule[d]->state == MATCHED) { - result = parser_rule_process_recipe(parser->rule[d]); - parser->rule[d]->state = USED; - break; + new_result = parser_rule_process_recipe(parser->rule[d]); + new_len = strlen(new_result); + //elog(NOTICE, "Is this it: %s ?", new_result); + if (new_len < result_len) { + parser->rule[d]->state = USED; + result_len = new_len; + result = new_result; + //elog(NOTICE, "It is!"); + } else + free(new_result); } return result; Common subdirectories: /home/ivoras/temp/dict_regex/sql and ./sql