--- trunk/pgswish.c 2005/02/19 12:27:04 11 +++ trunk/pgswish.c 2005/02/19 15:09:05 12 @@ -78,18 +78,15 @@ SRF_RETURN_DONE(funcctx); } - if ( SwishError( swish_handle ) ) error_or_abort( swish_handle ); + error_or_abort( swish_handle ); /* set ranking scheme. default is 0 */ SwishRankScheme( swish_handle, 0 ); - - /* Check for errors after every call */ - if ( SwishError( swish_handle ) ) - error_or_abort( swish_handle ); /* print an error or abort -- see below */ + error_or_abort( swish_handle ); elog(INFO, "pgswish: SwishQuery(%s)", query); /* Here's a short-cut to searching that creates a search object and searches at the same time */ swish_results = SwishQuery( swish_handle, query); - if ( SwishError( swish_handle ) ) error_or_abort( swish_handle ); + error_or_abort( swish_handle ); /* total number of tuples to be returned */ funcctx->max_calls = SwishHits( swish_results ); @@ -131,7 +128,6 @@ char **values; HeapTuple tuple; Datum result; - char *prop; SW_RESULT *sw_res; /* one row from swish-e results */ elog(INFO, "pgswish: in loop %d", call_cntr); @@ -142,14 +138,14 @@ } elog(INFO, "pgswish: check for swish-e error"); - if ( SwishError( swish_handle ) ) error_or_abort( swish_handle ); + error_or_abort( swish_handle ); /* * Prepare a values array for storage in our slot. * This should be an array of C strings which will * be processed later by the type input functions. */ - values = (char **) palloc(5 * sizeof(char *)); + values = (char **) palloc(4 * sizeof(char *)); sw_res = SwishNextResult( swish_results ); if (! sw_res) { @@ -157,41 +153,33 @@ SRF_RETURN_DONE(funcctx); } - elog(INFO, "Path: %s\n Rank: %lu\n Size: %lu\n Title: %s\n Index: %s\n Modified: %s\n Record #: %lu\n File #: %lu\n\n", - SwishResultPropertyStr ( sw_res, "swishdocpath" ), - SwishResultPropertyULong ( sw_res, "swishrank" ), - SwishResultPropertyULong ( sw_res, "swishdocsize" ), - SwishResultPropertyStr ( sw_res, "swishtitle"), - SwishResultPropertyStr ( sw_res, "swishdbfile" ), - SwishResultPropertyStr ( sw_res, "swishlastmodified" ), - SwishResultPropertyULong ( sw_res, "swishreccount" ), /* can figure this out in loop, of course */ - SwishResultPropertyULong ( sw_res, "swishfilenum" ) - ); - - elog(INFO, "pgswish: get prop"); - prop = SwishResultPropertyStr ( sw_res, "swishdocpath" ); - elog(INFO, "pgswish: got error?"); - if ( SwishError( swish_handle ) ) error_or_abort( swish_handle ); - elog(INFO, "swishdocpath: %s", prop); - -// values[0] = GET_STR( SwishResultPropertyULong ( sw_res, "swishrank" ) ); - values[0] = NULL; -// values[1] = GET_TEXT( SwishResultPropertyStr ( sw_res, "swishdocpath" ) ); -if (0) { - values[1] = GET_TEXT( SwishResultPropertyStr ( sw_res, "swishdocpath" ) ); - values[2] = _textout( SwishResultPropertyStr ( sw_res, "swishtitle" ) ); - values[3] = _textout( SwishResultPropertyStr ( sw_res, "swishdocsize" ) ); - values[4] = _textout( SwishResultPropertyStr ( sw_res, "swishdbfile" ) ); - + elog(INFO, "Path: %s\n Rank: %lu\n Size: %lu\n Title: %s\n Index: %s\n Modified: %s\n Record #: %lu\n File #: %lu\n\n", + SwishResultPropertyStr ( sw_res, "swishdocpath" ), + SwishResultPropertyULong ( sw_res, "swishrank" ), + SwishResultPropertyULong ( sw_res, "swishdocsize" ), + SwishResultPropertyStr ( sw_res, "swishtitle"), + SwishResultPropertyStr ( sw_res, "swishdbfile" ), + SwishResultPropertyStr ( sw_res, "swishlastmodified" ), + SwishResultPropertyULong ( sw_res, "swishreccount" ), /* can figure this out in loop, of course */ + SwishResultPropertyULong ( sw_res, "swishfilenum" ) + ); + + elog(INFO, "swishdocpath: %s", prop2text( sw_res, "swishdocpath" ) ); + values[0] = prop2int( sw_res, "swishrank" ); + values[1] = prop2text( sw_res, "swishdocpath" ); + values[2] = prop2text( sw_res, "swishtitle" ); + values[3] = prop2int( sw_res, "swishdocsize" ); + /* build a tuple */ tuple = BuildTupleFromCStrings(attinmeta, values); /* make the tuple into a datum */ result = TupleGetDatum(slot, tuple); -} - /* clean up (this is not really necessary) */ + /* clean up ? */ + elog(INFO, "row: %s|%s|%s|%s",values[0],values[1],values[2],values[3]); + SRF_RETURN_NEXT(funcctx, result); } else { /* free swish object and close */ @@ -208,6 +196,60 @@ * */ +char *prop2text(SW_RESULT sw_res, char *propname) { + char *val; + char *prop; + int len; + + elog(INFO, "prop2text(%s)", propname); + + prop = SwishResultPropertyStr( sw_res, propname ); + error_or_abort( swish_handle ); + + len = strlen(prop); + elog(INFO, "prop2text(%s) = '%s' %d bytes", propname, prop, len); + + len++; + len *= sizeof(char); + + elog(INFO, "palloc(%d)", len); + + val = palloc(len); + + memset(val, 0, len); + strncpy(val, prop, len); + + elog(INFO, "val=%s", val); + + return val; +} + +char *prop2int(SW_RESULT sw_res, char *propname) { + char *val; + unsigned long prop; + int len; + + elog(INFO, "prop2int(%s)", propname); + + prop = SwishResultPropertyULong( sw_res, propname ); + error_or_abort( swish_handle ); + + elog(INFO, "prop2int(%s) = %lu", propname, prop); + + len = 128 * sizeof(char); + elog(INFO, "palloc(%d)", len); + + val = palloc(len); + memset(val, 0, len); + + snprintf(val, len, "%lu", prop); + + elog(INFO, "val=%s", val); + + return val; +} + + static void error_or_abort( SW_HANDLE swish_handle ) { if ( !SwishError( swish_handle ) ) return;