--- trunk/pgest.c 2005/09/11 21:44:56 47 +++ trunk/pgest.c 2005/10/29 18:54:40 49 @@ -355,10 +355,24 @@ * */ +/* select * from pgest( */ +#define _arg_node_uri 0 +#define _arg_login 1 +#define _arg_passwd 2 +#define _arg_depth 3 +#define _arg_query 4 +#define _arg_attr 5 +#define _arg_order 6 +#define _arg_limit 7 +#define _arg_offset 8 +#define _arg_attr_array 9 +/* as (foo text, ... ); */ + + PG_FUNCTION_INFO_V1(pgest_node); Datum pgest_node(PG_FUNCTION_ARGS) { - ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(8); + ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(_arg_attr_array); Oid attr_element_type = ARR_ELEMTYPE(attr_arr); int attr_ndims = ARR_NDIM(attr_arr); int *attr_dim_counts = ARR_DIMS(attr_arr); @@ -389,6 +403,7 @@ int resnum = 0; int limit = 0; int offset = 0; + int depth = 0; char *node_url; char *user, *passwd; @@ -448,58 +463,65 @@ /* take rest of arguments from function */ /* node URL */ - if (PG_ARGISNULL(0)) { + if (PG_ARGISNULL(_arg_node_uri)) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("node URL can't be null"), errdetail("Node URL must be valid URL to HyperEstraier node"))); } - node_url = _textout(PG_GETARG_TEXT_P(0)); + node_url = _textout(PG_GETARG_TEXT_P(_arg_node_uri)); /* login and password */ - if (PG_ARGISNULL(1) || PG_ARGISNULL(2)) { + if (PG_ARGISNULL(_arg_login) || PG_ARGISNULL(_arg_passwd)) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("username and password can't be NULL"), errdetail("You must specify valid username and password to HyperEstraier node"))); } - user = _textout(PG_GETARG_TEXT_P(1)); - passwd = _textout(PG_GETARG_TEXT_P(2)); + user = _textout(PG_GETARG_TEXT_P(_arg_login)); + passwd = _textout(PG_GETARG_TEXT_P(_arg_passwd)); + + /* depth of search */ + if (PG_ARGISNULL(_arg_depth)) { + depth = 0; + } else { + depth = PG_GETARG_INT32(_arg_depth); + } /* query string */ - if (PG_ARGISNULL(3)) { + if (PG_ARGISNULL(_arg_query)) { query = ""; } else { - query = _textout(PG_GETARG_TEXT_P(3)); + query = _textout(PG_GETARG_TEXT_P(_arg_query)); } /* atribute filter */ - if (PG_ARGISNULL(4)) { + if (PG_ARGISNULL(_arg_attr)) { attr = ""; } else { - attr = _textout(PG_GETARG_TEXT_P(4)); + attr = _textout(PG_GETARG_TEXT_P(_arg_attr)); } /* sort order */ - if (PG_ARGISNULL(5)) { + if (PG_ARGISNULL(_arg_order)) { order = ""; } else { - order = _textout(PG_GETARG_TEXT_P(5)); + order = _textout(PG_GETARG_TEXT_P(_arg_order)); } /* limit */ - if (PG_ARGISNULL(6)) { + if (PG_ARGISNULL(_arg_limit)) { limit = 0; } else { - limit = PG_GETARG_INT32(6); + limit = PG_GETARG_INT32(_arg_limit); } /* offset */ - if (PG_ARGISNULL(7)) { + if (PG_ARGISNULL(_arg_offset)) { offset = 0; } else { - offset = PG_GETARG_INT32(7); + offset = PG_GETARG_INT32(_arg_offset); } /* initialize the network environment */ @@ -513,7 +535,7 @@ node = est_node_new(node_url); est_node_set_auth(node, user, passwd); - elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(4) ? "NULL" : attr), limit, offset); + elog(DEBUG1, "pgest_node: node: %s (d:%d) query[%s] attr[%s] limit %d offset %d", node_url, depth, query, (PG_ARGISNULL(_arg_attr) ? "NULL" : attr), limit, offset); /* create a search condition object */ if (!(cond = est_cond_new())) { @@ -522,11 +544,11 @@ } /* set the search phrase to the search condition object */ - if (! PG_ARGISNULL(3) && strlen(query) > 0) + if (! PG_ARGISNULL(_arg_query) && strlen(query) > 0) est_cond_set_phrase(cond, query); /* minimum valid attribute length is 10: @a STREQ a */ - if (! PG_ARGISNULL(4) && strlen(attr) >= 10) { + if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) { elog(DEBUG1,"attributes: %s", attr); char *curr_attr; curr_attr = strtok(attr, ATTR_DELIMITER); @@ -538,7 +560,7 @@ } /* set the search phrase to the search condition object */ - if (! PG_ARGISNULL(5) && strlen(order) > 0) { + if (! PG_ARGISNULL(_arg_order) && strlen(order) > 0) { elog(DEBUG1,"est_cond_set_order(%s)", order); est_cond_set_order(cond, order); } @@ -549,8 +571,7 @@ } /* get the result of search */ - /* FIXME: allow user to specify depath of search */ - nres = est_node_search(node, cond, 0); + nres = est_node_search(node, cond, depth); if (! nres) { int status = est_node_status(node);