--- trunk/pgest.c 2005/05/25 23:28:15 11 +++ trunk/pgest.c 2005/05/25 23:38:37 12 @@ -63,19 +63,40 @@ if (SRF_IS_FIRSTCALL()) { MemoryContext oldcontext; - /* take arguments from function */ - //index_path = _textout(PG_GETARG_TEXT_P(0)); - index_path = _textout(PG_GETARG_TEXT_P(0)); - query = _textout(PG_GETARG_TEXT_P(1)); - attr = _textout(PG_GETARG_TEXT_P(2)); - limit = PG_GETARG_INT32(3); - offset = PG_GETARG_INT32(4); - /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); /* switch to memory context appropriate for multiple function calls */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + /* take arguments from function */ + + /* index path */ + if (PG_ARGISNULL(0)) { + elog(ERROR, "index path can't be null"); + SRF_RETURN_DONE(funcctx); + } + index_path = _textout(PG_GETARG_TEXT_P(0)); + + /* query string */ + if (PG_ARGISNULL(0)) { + query = ""; + } else { + query = _textout(PG_GETARG_TEXT_P(1)); + } + + /* atribute filter */ + if (PG_ARGISNULL(2)) { + attr = ""; + } else { + attr = _textout(PG_GETARG_TEXT_P(2)); + } + + /* limit */ + if (! PG_ARGISNULL(3)) limit = PG_GETARG_INT32(3); + + /* offset */ + if (! PG_ARGISNULL(4)) offset = PG_GETARG_INT32(4); + /* open the database */ elog(DEBUG1, "pgest: est_db_open(%s)", index_path); @@ -85,7 +106,7 @@ SRF_RETURN_DONE(funcctx); } - elog(INFO, "pgest: query[%s] attr[%s] limit %d offset %d", query, attr, limit, offset); + elog(INFO, "pgest: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(2) ? "NULL" : attr), limit, offset); /* create a search condition object */ if (!(cond = est_cond_new())) { @@ -94,11 +115,11 @@ } /* set the search phrase to the search condition object */ - if (strlen(query) > 0) + if (! PG_ARGISNULL(1) && strlen(query) > 0) est_cond_set_phrase(cond, query); /* minimum valid attribute length is 10: @a STREQ a */ - if (attr != NULL && strlen(attr) >= 10) { + if (! PG_ARGISNULL(2) && strlen(attr) >= 10) { elog(INFO,"est_cond_add_attr(%s)", attr); est_cond_add_attr(cond, attr); }