--- trunk/pgest.c 2005/05/20 13:00:46 2 +++ trunk/pgest.c 2005/05/20 18:45:01 4 @@ -40,6 +40,8 @@ ESTDOC *doc; const CBLIST *texts; int ecode, *est_result, resnum, i, j; +int limit = 0; +int offset = 0; /* define PostgreSQL v1 function */ PG_FUNCTION_INFO_V1(pgest); @@ -62,6 +64,8 @@ //index_path = _textout(PG_GETARG_TEXT_P(0)); index_path = _textout(PG_GETARG_TEXT_P(0)); query = _textout(PG_GETARG_TEXT_P(1)); + limit = PG_GETARG_INT32(2); + offset = PG_GETARG_INT32(3); /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); @@ -77,7 +81,7 @@ SRF_RETURN_DONE(funcctx); } - elog(DEBUG2, "pgest: query=%s", query); + elog(INFO, "pgest: query=%s limit %d offset %d", query, limit, offset); /* create a search condition object */ if (!(cond = est_cond_new())) { @@ -128,7 +132,12 @@ max_calls = funcctx->max_calls; slot = funcctx->slot; attinmeta = funcctx->attinmeta; - + + if (limit && call_cntr > limit - 1) { + elog(INFO, "call_cntr: %d limit: %d", call_cntr, limit); + SRF_RETURN_DONE(funcctx); + } + if (call_cntr < max_calls) { char **values; HeapTuple tuple; @@ -147,7 +156,7 @@ * be processed later by the type input functions. */ - if (doc = est_db_get_doc(db, est_result[call_cntr], 0)) { + if (doc = est_db_get_doc(db, est_result[call_cntr + offset], 0)) { elog(DEBUG1, "URI: %s\n Title: %s\n", est_doc_attr(doc, "@uri"), @@ -292,11 +301,12 @@ char *val; const char *attrval; int len; + int attrlen; elog(DEBUG1, "doc: %08x, attr: %s", doc, attr); - if (attrval = est_doc_attr(doc, attr)) { - val = (char *) palloc(strlen(attrval) * sizeof(char)); + if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) { + val = (char *) palloc(attrlen * sizeof(char)); } else { return (Datum) NULL; }