--- trunk/pgest.c 2006/08/07 11:14:52 61 +++ trunk/pgest.c 2006/08/08 11:42:01 79 @@ -634,7 +634,7 @@ /* skip HINTS. prefix */ hint += strlen(HINTS_PREFIX); - hint_val = cbmapget(hints, hint, -1, NULL); + hint_val = (char *)cbmapget(hints, hint, -1, NULL); elog(DEBUG2, "hint %s = %s", hint, hint_val); if (hint_val != NULL) { @@ -724,7 +724,7 @@ char *next; char *curr_attr; while ( strlen(attr) > 0 ) { - printf("len [%s] = %d\n", attr, strlen(attr)); + printf("len [%s] = %zd\n", attr, strlen(attr)); if ((next = strstr(attr, ATTR_DELIMITER)) != NULL) { curr_attr = palloc( next - attr + 1 ); memcpy(curr_attr, attr, next-attr); @@ -768,6 +768,7 @@ int knumber; int i; int create_doc = 0; + int edit_doc = 0; ESTNODE *node; ESTDOC *doc; @@ -810,7 +811,7 @@ } else if (TRIGGER_FIRED_BY_UPDATE(data->tg_event)) { ret = data->tg_newtuple; - create_doc++; + edit_doc++; } else if (TRIGGER_FIRED_BY_DELETE(data->tg_event)) { /* There is no new data */ @@ -823,13 +824,21 @@ elog(ERROR, "pgest_trigger() not called from INSERT/UPDATE/DELETE"); } - if ( create_doc ) { + if ( create_doc || edit_doc ) { - /* create a document object */ - doc = est_doc_new(); - est_doc_add_attr(doc, "@uri", key); + if ( create_doc ) { + /* create a document object */ + doc = est_doc_new(); + est_doc_add_attr(doc, "@uri", key); - elog(DEBUG1, "est_doc_new @uri=%s", key); + elog(DEBUG1, "est_doc_new @uri=%s", key); + } else { + /* edit existing document */ + doc = est_node_get_doc_by_uri(node, key); + if (doc == NULL) + elog(ERROR, "est_node_get_doc_by_uri(%s): %d\n", key, est_node_status(node)); + elog(DEBUG1, "est_node_get_doc_by_uri(%s)", key); + } for( i = 4; i < data->tg_trigger->tgnargs; i++ ) { @@ -843,9 +852,15 @@ } - /* register the document object to the node */ - if( ! est_node_put_doc(node, doc) ) - elog(ERROR, "est_node_put_doc: %d\n", est_node_status(node)); + if ( edit_doc ) { + /* update existing document */ + if( ! est_node_edit_doc(node, doc) ) + elog(ERROR, "est_node_edit_doc: %d\n", est_node_status(node)); + } else { + /* register the document object to the node */ + if( ! est_node_put_doc(node, doc) ) + elog(ERROR, "est_node_put_doc: %d\n", est_node_status(node)); + } /* destroy the document object */ est_doc_delete(doc);