--- trunk/pgest.c 2005/06/30 20:01:36 27 +++ trunk/pgest.c 2005/07/06 14:47:56 31 @@ -47,7 +47,7 @@ PG_FUNCTION_INFO_V1(pgest_attr); Datum pgest_attr(PG_FUNCTION_ARGS) { - ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(5); + ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(6); Oid attr_element_type = ARR_ELEMTYPE(attr_arr); int attr_ndims = ARR_NDIM(attr_arr); int *attr_dim_counts = ARR_DIMS(attr_arr); @@ -81,6 +81,7 @@ char *index_path; char *query; char *attr; + char *order; /* only allow 1D input array */ @@ -143,7 +144,7 @@ index_path = _textout(PG_GETARG_TEXT_P(0)); /* query string */ - if (PG_ARGISNULL(0)) { + if (PG_ARGISNULL(1)) { query = ""; } else { query = _textout(PG_GETARG_TEXT_P(1)); @@ -155,19 +156,27 @@ } else { attr = _textout(PG_GETARG_TEXT_P(2)); } + + /* sort order */ + if (PG_ARGISNULL(3)) { + order = ""; + } else { + order = _textout(PG_GETARG_TEXT_P(3)); + } + /* limit */ - if (PG_ARGISNULL(3)) { + if (PG_ARGISNULL(4)) { limit = 0; } else { - limit = PG_GETARG_INT32(3); + limit = PG_GETARG_INT32(4); } /* offset */ - if (PG_ARGISNULL(4)) { + if (PG_ARGISNULL(5)) { offset = 0; } else { - offset = PG_GETARG_INT32(4); + offset = PG_GETARG_INT32(5); } @@ -198,6 +207,12 @@ est_cond_add_attr(cond, attr); } + /* set the search phrase to the search condition object */ + if (! PG_ARGISNULL(3) && strlen(order) > 0) { + elog(DEBUG1,"est_cond_set_order(%s)", order); + est_cond_set_order(cond, order); + } + /* get the result of search */ est_result = est_db_search(db, cond, &resnum, NULL); @@ -208,7 +223,7 @@ /* total number of tuples to be returned */ if (limit && limit < resnum) { - nrows = limit - offset; + nrows = limit; } else { nrows = resnum - offset; } @@ -274,6 +289,8 @@ rsinfo->setDesc = tupdesc; MemoryContextSwitchTo(oldcontext); + est_cond_delete(cond); + if(!est_db_close(db, &ecode)){ ereport(ERROR, (errcode(ERRCODE_IO_ERROR), errmsg("est_db_close: %d", ecode),