--- trunk/pgest.c 2005/05/20 19:44:09 5 +++ trunk/pgest.c 2005/05/26 00:06:10 14 @@ -63,19 +63,48 @@ 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 = 0; + } else { + limit = PG_GETARG_INT32(3); + } + + /* offset */ + if (PG_ARGISNULL(4)) { + offset = 0; + } else { + offset = PG_GETARG_INT32(4); + } + /* open the database */ elog(DEBUG1, "pgest: est_db_open(%s)", index_path); @@ -85,7 +114,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,10 +123,11 @@ } /* set the search phrase to the search condition object */ - est_cond_set_phrase(cond, query); + 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); } @@ -191,10 +221,10 @@ est_doc_delete(doc); } else { elog(INFO, "no result from estraier"); - values[0] = NULL; - values[1] = NULL; - values[2] = NULL; - values[3] = NULL; + values[0] = DatumGetCString( "" ); + values[1] = DatumGetCString( "" ); + values[2] = DatumGetCString( "" ); + values[3] = DatumGetCString( "" ); }