/[pgswish]/trunk/pgswish.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/pgswish.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 18 by dpavlin, Sun Feb 20 22:58:25 2005 UTC revision 19 by dpavlin, Sun Mar 6 21:13:39 2005 UTC
# Line 6  Line 6 
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
# Line 34  Line 36 
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 */
# Line 81  Datum pgswish(PG_FUNCTION_ARGS) { Line 82  Datum pgswish(PG_FUNCTION_ARGS) {
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 );
# Line 142  Datum pgswish(PG_FUNCTION_ARGS) { Line 143  Datum pgswish(PG_FUNCTION_ARGS) {
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.
# Line 153  Datum pgswish(PG_FUNCTION_ARGS) { Line 154  Datum pgswish(PG_FUNCTION_ARGS) {
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                                    
# Line 292  Datum pgswish2(PG_FUNCTION_ARGS) Line 295  Datum pgswish2(PG_FUNCTION_ARGS)
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;
# Line 301  char *prop2text(SW_RESULT sw_res, char * Line 304  char *prop2text(SW_RESULT sw_res, char *
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);
# Line 330  char *prop2int(SW_RESULT sw_res, char *p Line 333  char *prop2int(SW_RESULT sw_res, char *p
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    
# Line 351  char *prop2int(SW_RESULT sw_res, char *p Line 354  char *prop2int(SW_RESULT sw_res, char *p
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,
# Line 362  static void error_or_abort( SW_HANDLE sw Line 365  static void error_or_abort( SW_HANDLE sw
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    

Legend:
Removed from v.18  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.26