/[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 11 by dpavlin, Sat Feb 19 12:27:04 2005 UTC revision 12 by dpavlin, Sat Feb 19 15:09:05 2005 UTC
# Line 78  Datum pgswish(PG_FUNCTION_ARGS) { Line 78  Datum pgswish(PG_FUNCTION_ARGS) {
78                          SRF_RETURN_DONE(funcctx);                          SRF_RETURN_DONE(funcctx);
79                  }                  }
80                                    
81                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  error_or_abort( swish_handle );
82                  /* set ranking scheme. default is 0 */                  /* set ranking scheme. default is 0 */
83                  SwishRankScheme( swish_handle, 0 );                  SwishRankScheme( swish_handle, 0 );
84                    error_or_abort( swish_handle );
                 /* Check for errors after every call */  
                 if ( SwishError( swish_handle ) )  
                         error_or_abort( swish_handle );  /* print an error or abort -- see below */  
85    
86                  elog(INFO, "pgswish: SwishQuery(%s)", query);                  elog(INFO, "pgswish: SwishQuery(%s)", query);
87                  /* 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 */
88                  swish_results = SwishQuery( swish_handle, query);                  swish_results = SwishQuery( swish_handle, query);
89                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  error_or_abort( swish_handle );
90    
91                  /* total number of tuples to be returned */                  /* total number of tuples to be returned */
92                  funcctx->max_calls = SwishHits( swish_results );                  funcctx->max_calls = SwishHits( swish_results );
# Line 131  Datum pgswish(PG_FUNCTION_ARGS) { Line 128  Datum pgswish(PG_FUNCTION_ARGS) {
128                  char            **values;                  char            **values;
129                  HeapTuple       tuple;                  HeapTuple       tuple;
130                  Datum           result;                  Datum           result;
                 char            *prop;  
131                  SW_RESULT       *sw_res;        /* one row from swish-e results */                  SW_RESULT       *sw_res;        /* one row from swish-e results */
132    
133                  elog(INFO, "pgswish: in loop %d", call_cntr);                  elog(INFO, "pgswish: in loop %d", call_cntr);
# Line 142  Datum pgswish(PG_FUNCTION_ARGS) { Line 138  Datum pgswish(PG_FUNCTION_ARGS) {
138                  }                  }
139                                    
140                  elog(INFO, "pgswish: check for swish-e error");                  elog(INFO, "pgswish: check for swish-e error");
141                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  error_or_abort( swish_handle );
142    
143                  /*                  /*
144                   * Prepare a values array for storage in our slot.                   * Prepare a values array for storage in our slot.
145                   * This should be an array of C strings which will                   * This should be an array of C strings which will
146                   * be processed later by the type input functions.                   * be processed later by the type input functions.
147                   */                   */
148                  values = (char **) palloc(5 * sizeof(char *));                  values = (char **) palloc(4 * sizeof(char *));
149    
150                  sw_res = SwishNextResult( swish_results );                  sw_res = SwishNextResult( swish_results );
151                  if (! sw_res) {                  if (! sw_res) {
# Line 157  Datum pgswish(PG_FUNCTION_ARGS) { Line 153  Datum pgswish(PG_FUNCTION_ARGS) {
153                          SRF_RETURN_DONE(funcctx);                          SRF_RETURN_DONE(funcctx);
154                  }                  }
155                                    
156          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",                  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",
157              SwishResultPropertyStr   ( sw_res, "swishdocpath" ),                          SwishResultPropertyStr   ( sw_res, "swishdocpath" ),
158              SwishResultPropertyULong ( sw_res, "swishrank" ),                          SwishResultPropertyULong ( sw_res, "swishrank" ),
159              SwishResultPropertyULong ( sw_res, "swishdocsize" ),                          SwishResultPropertyULong ( sw_res, "swishdocsize" ),
160              SwishResultPropertyStr   ( sw_res, "swishtitle"),                          SwishResultPropertyStr   ( sw_res, "swishtitle"),
161              SwishResultPropertyStr   ( sw_res, "swishdbfile" ),                          SwishResultPropertyStr   ( sw_res, "swishdbfile" ),
162              SwishResultPropertyStr   ( sw_res, "swishlastmodified" ),                          SwishResultPropertyStr   ( sw_res, "swishlastmodified" ),
163              SwishResultPropertyULong ( sw_res, "swishreccount" ),  /* can figure this out in loop, of course */                          SwishResultPropertyULong ( sw_res, "swishreccount" ),  /* can figure this out in loop, of course */
164              SwishResultPropertyULong ( sw_res, "swishfilenum" )                          SwishResultPropertyULong ( sw_res, "swishfilenum" )
165          );                  );
166    
167                  elog(INFO, "pgswish: get prop");                  elog(INFO, "swishdocpath: %s", prop2text( sw_res, "swishdocpath" ) );
168                  prop = SwishResultPropertyStr ( sw_res, "swishdocpath" );                  values[0] = prop2int( sw_res, "swishrank" );
169                  elog(INFO, "pgswish: got error?");                  values[1] = prop2text( sw_res, "swishdocpath" );
170                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  values[2] = prop2text( sw_res, "swishtitle" );
171                  elog(INFO, "swishdocpath: %s", prop);                  values[3] = prop2int( sw_res, "swishdocsize" );
172                    
 //              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" ) );  
   
173                  /* build a tuple */                  /* build a tuple */
174                  tuple = BuildTupleFromCStrings(attinmeta, values);                  tuple = BuildTupleFromCStrings(attinmeta, values);
175    
176                  /* make the tuple into a datum */                  /* make the tuple into a datum */
177                  result = TupleGetDatum(slot, tuple);                  result = TupleGetDatum(slot, tuple);
178    
179  }                  /* clean up ? */
                 /* clean up (this is not really necessary) */  
180    
181                    elog(INFO, "row: %s|%s|%s|%s",values[0],values[1],values[2],values[3]);
182            
183                  SRF_RETURN_NEXT(funcctx, result);                  SRF_RETURN_NEXT(funcctx, result);
184          } else {          } else {
185                  /* free swish object and close */                  /* free swish object and close */
# Line 208  if (0) { Line 196  if (0) {
196   *   *
197   */   */
198    
199    char *prop2text(SW_RESULT sw_res, char *propname) {
200            char *val;
201            char *prop;
202            int len;
203    
204            elog(INFO, "prop2text(%s)", propname);
205    
206            prop = SwishResultPropertyStr( sw_res, propname );
207            error_or_abort( swish_handle );
208    
209            len = strlen(prop);
210            elog(INFO, "prop2text(%s) = '%s' %d bytes", propname, prop, len);
211    
212            len++;
213            len *= sizeof(char);
214    
215            elog(INFO, "palloc(%d)", len);
216    
217            val = palloc(len);
218    
219            memset(val, 0, len);
220            strncpy(val, prop, len);
221    
222            elog(INFO, "val=%s", val);
223    
224            return val;
225    }
226    
227    char *prop2int(SW_RESULT sw_res, char *propname) {
228            char *val;
229            unsigned long prop;
230            int len;
231    
232            elog(INFO, "prop2int(%s)", propname);
233    
234            prop = SwishResultPropertyULong( sw_res, propname );
235            error_or_abort( swish_handle );
236    
237            elog(INFO, "prop2int(%s) = %lu", propname, prop);
238    
239            len = 128 * sizeof(char);
240            elog(INFO, "palloc(%d)", len);
241    
242            val = palloc(len);
243            memset(val, 0, len);
244    
245            snprintf(val, len, "%lu", prop);
246    
247            elog(INFO, "val=%s", val);
248    
249            return val;
250    }
251    
252    
253  static void error_or_abort( SW_HANDLE swish_handle ) {  static void error_or_abort( SW_HANDLE swish_handle ) {
254          if ( !SwishError( swish_handle ) )          if ( !SwishError( swish_handle ) )
255                  return;                  return;

Legend:
Removed from v.11  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26