--- trunk/pgest.c 2006/05/09 22:55:42 51 +++ trunk/pgest.c 2006/05/11 15:52:50 56 @@ -25,6 +25,7 @@ #include "funcapi.h" #include "utils/builtins.h" #include "utils/array.h" +#include "utils/lsyscache.h" #include "miscadmin.h" #include #include @@ -45,6 +46,7 @@ /* prototype */ char *attr2text(ESTDOC *doc, char *attr); char *node_attr2text(ESTRESDOC *rdoc, char *attr); +void cond_add_attr(ESTCOND *cond, char *attr); /* work in progress */ @@ -77,7 +79,6 @@ ESTDB *db; ESTCOND *cond; ESTDOC *doc; - const CBLIST *texts; int ecode, *est_result, resnum; int limit = 0; int offset = 0; @@ -208,13 +209,7 @@ /* minimum valid attribute length is 10: @a STREQ a */ if (! PG_ARGISNULL(2) && strlen(attr) >= 10) { elog(DEBUG1,"attributes: %s", attr); - char *curr_attr; - curr_attr = strtok(attr, ATTR_DELIMITER); - while (curr_attr) { - elog(DEBUG1,"est_cond_add_attr(%s)", curr_attr); - est_cond_add_attr(cond, curr_attr); - curr_attr = strtok(NULL, ATTR_DELIMITER); - } + cond_add_attr(cond, attr); } /* set the search phrase to the search condition object */ @@ -323,7 +318,7 @@ if (! doc) return (Datum) NULL; - elog(DEBUG1, "doc: %08x, attr: %s", doc, attr); + elog(DEBUG1, "doc: %p, attr: %s", doc, attr); if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) { val = (char *) palloc(attrlen * sizeof(char)); @@ -399,7 +394,6 @@ ESTCOND *cond; ESTNODERES *nres; ESTRESDOC *rdoc; - const CBLIST *texts; int resnum = 0; int limit = 0; int offset = 0; @@ -550,13 +544,7 @@ /* minimum valid attribute length is 10: @a STREQ a */ if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) { elog(DEBUG1,"attributes: %s", attr); - char *curr_attr; - curr_attr = strtok(attr, ATTR_DELIMITER); - while (curr_attr) { - elog(DEBUG1,"est_cond_add_attr(%s)", curr_attr); - est_cond_add_attr(cond, curr_attr); - curr_attr = strtok(NULL, ATTR_DELIMITER); - } + cond_add_attr(cond, attr); } /* set the search phrase to the search condition object */ @@ -683,7 +671,7 @@ if (! rdoc) return (Datum) NULL; - elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr); + elog(DEBUG1, "doc: %p, attr: %s", rdoc, attr); if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) { val = (char *) palloc(attrlen * sizeof(char)); @@ -709,3 +697,23 @@ return val; } +/* parse attributes and add them to confition */ +void cond_add_attr(ESTCOND *cond, char *attr) { + char *next; + char *curr_attr; + while ( strlen(attr) > 0 ) { + printf("len [%s] = %d\n", attr, strlen(attr)); + if ((next = strstr(attr, ATTR_DELIMITER)) != NULL) { + curr_attr = palloc( next - attr + 1 ); + memcpy(curr_attr, attr, next-attr); + curr_attr[next-attr] = '\0'; + next += strlen(ATTR_DELIMITER); + } else { + next = ""; + curr_attr = attr; + } + elog(DEBUG1, "est_cond_add_attr(%s)", curr_attr); + est_cond_add_attr(cond, curr_attr); + attr = next; + } +}