6 |
* TODO: |
* TODO: |
7 |
* - check null input using PG_ARGISNULL before using PG_GETARG_xxxx |
* - check null input using PG_ARGISNULL before using PG_GETARG_xxxx |
8 |
* - support composite type arguments |
* - support composite type arguments |
9 |
|
* - split error_or_abort |
10 |
|
* - use getResultPropValue not SwishResultPropertyStr |
11 |
* |
* |
12 |
* NOTES: |
* NOTES: |
13 |
* - clear structures with memset to support hash indexes (who whould like |
* - clear structures with memset to support hash indexes (who whould like |
36 |
#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp))) |
#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp))) |
37 |
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp))) |
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp))) |
38 |
|
|
|
|
|
39 |
SW_HANDLE swish_handle = NULL;/* Database handle */ |
SW_HANDLE swish_handle = NULL;/* Database handle */ |
40 |
SW_SEARCH search = NULL; /* search handle -- holds search parameters */ |
SW_SEARCH search = NULL; /* search handle -- holds search parameters */ |
41 |
SW_RESULTS swish_results = NULL; /* results handle -- holds list of results */ |
SW_RESULTS swish_results = NULL; /* results handle -- holds list of results */ |
82 |
SRF_RETURN_DONE(funcctx); |
SRF_RETURN_DONE(funcctx); |
83 |
} |
} |
84 |
|
|
85 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) SRF_RETURN_DONE(funcctx); |
86 |
/* set ranking scheme. default is 0 */ |
/* set ranking scheme. default is 0 */ |
87 |
SwishRankScheme( swish_handle, 0 ); |
SwishRankScheme( swish_handle, 0 ); |
88 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) SRF_RETURN_DONE(funcctx); |
89 |
|
|
90 |
elog(INFO, "pgswish: SwishQuery(%s)", query); |
elog(INFO, "pgswish: SwishQuery(%s)", query); |
91 |
/* Here's a short-cut to searching that creates a search object and searches at the same time */ |
/* Here's a short-cut to searching that creates a search object and searches at the same time */ |
92 |
swish_results = SwishQuery( swish_handle, query); |
swish_results = SwishQuery( swish_handle, query); |
93 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) SRF_RETURN_DONE(funcctx); |
94 |
|
|
95 |
/* total number of tuples to be returned */ |
/* total number of tuples to be returned */ |
96 |
funcctx->max_calls = SwishHits( swish_results ); |
funcctx->max_calls = SwishHits( swish_results ); |
143 |
} |
} |
144 |
|
|
145 |
elog(DEBUG1, "pgswish: check for swish-e error"); |
elog(DEBUG1, "pgswish: check for swish-e error"); |
146 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) SRF_RETURN_DONE(funcctx); |
147 |
|
|
148 |
/* |
/* |
149 |
* Prepare a values array for storage in our slot. |
* Prepare a values array for storage in our slot. |
154 |
sw_res = SwishNextResult( swish_results ); |
sw_res = SwishNextResult( swish_results ); |
155 |
if (! sw_res) { |
if (! sw_res) { |
156 |
elog(ERROR, "pgswish: swish-e sort result list: %d rows expected %d", call_cntr, max_calls - 1); |
elog(ERROR, "pgswish: swish-e sort result list: %d rows expected %d", call_cntr, max_calls - 1); |
157 |
|
Free_Results_Object( swish_results ); |
158 |
|
Free_Search_Object( search ); |
159 |
SRF_RETURN_DONE(funcctx); |
SRF_RETURN_DONE(funcctx); |
160 |
} |
} |
161 |
|
|
295 |
} |
} |
296 |
|
|
297 |
|
|
298 |
/* make text var prom property */ |
/* make text var from property */ |
299 |
char *prop2text(SW_RESULT sw_res, char *propname) { |
char *prop2text(SW_RESULT sw_res, char *propname) { |
300 |
char *val; |
char *val; |
301 |
char *prop; |
char *prop; |
304 |
elog(DEBUG2, "prop2text(%s)", propname); |
elog(DEBUG2, "prop2text(%s)", propname); |
305 |
|
|
306 |
prop = SwishResultPropertyStr( sw_res, propname ); |
prop = SwishResultPropertyStr( sw_res, propname ); |
307 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) return NULL; |
308 |
|
|
309 |
len = strlen(prop); |
len = strlen(prop); |
310 |
elog(DEBUG1, "prop2text(%s) = '%s' %d bytes", propname, prop, len); |
elog(DEBUG1, "prop2text(%s) = '%s' %d bytes", propname, prop, len); |
333 |
elog(DEBUG2, "prop2int(%s)", propname); |
elog(DEBUG2, "prop2int(%s)", propname); |
334 |
|
|
335 |
prop = SwishResultPropertyULong( sw_res, propname ); |
prop = SwishResultPropertyULong( sw_res, propname ); |
336 |
error_or_abort( swish_handle ); |
if (error_or_abort( swish_handle )) return NULL; |
337 |
|
|
338 |
elog(DEBUG1, "prop2int(%s) = %lu", propname, prop); |
elog(DEBUG1, "prop2int(%s) = %lu", propname, prop); |
339 |
|
|
354 |
/* |
/* |
355 |
* check if swish has returned error, and elog it. |
* check if swish has returned error, and elog it. |
356 |
*/ |
*/ |
357 |
static void error_or_abort( SW_HANDLE swish_handle ) { |
static int error_or_abort( SW_HANDLE swish_handle ) { |
358 |
if ( !SwishError( swish_handle ) ) |
if ( !SwishError( swish_handle ) ) |
359 |
return; |
return 0; |
360 |
|
|
361 |
/* print a message */ |
/* print a message */ |
362 |
elog(ERROR, |
elog(ERROR, |
365 |
SwishErrorString( swish_handle ), |
SwishErrorString( swish_handle ), |
366 |
SwishLastErrorMsg( swish_handle ) |
SwishLastErrorMsg( swish_handle ) |
367 |
); |
); |
368 |
|
if ( swish_results ) Free_Results_Object( swish_results ); |
369 |
if ( search ) Free_Search_Object( search ); |
if ( search ) Free_Search_Object( search ); |
370 |
SwishClose( swish_handle ); |
SwishClose( swish_handle ); |
371 |
|
|
372 |
|
return 1; |
373 |
} |
} |
374 |
|
|