/[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 13 by dpavlin, Sat Feb 19 16:01:46 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 117  Datum pgswish(PG_FUNCTION_ARGS) { Line 114  Datum pgswish(PG_FUNCTION_ARGS) {
114                  funcctx->attinmeta = attinmeta;                  funcctx->attinmeta = attinmeta;
115    
116                  MemoryContextSwitchTo(oldcontext);                  MemoryContextSwitchTo(oldcontext);
117    
118                    elog(INFO, "SRF_IS_FIRSTCALL done");
119          }          }
120    
121          /* stuff done on every call of the function */          /* stuff done on every call of the function */
# Line 131  Datum pgswish(PG_FUNCTION_ARGS) { Line 130  Datum pgswish(PG_FUNCTION_ARGS) {
130                  char            **values;                  char            **values;
131                  HeapTuple       tuple;                  HeapTuple       tuple;
132                  Datum           result;                  Datum           result;
                 char            *prop;  
133                  SW_RESULT       *sw_res;        /* one row from swish-e results */                  SW_RESULT       *sw_res;        /* one row from swish-e results */
134    
135                  elog(INFO, "pgswish: in loop %d", call_cntr);                  elog(INFO, "pgswish: loop count %d", call_cntr);
136    
137                  if (! swish_results) {                  if (! swish_results) {
138                          elog(ERROR, "pgswish: no swish-e results");                          elog(ERROR, "pgswish: no swish-e results");
# Line 142  Datum pgswish(PG_FUNCTION_ARGS) { Line 140  Datum pgswish(PG_FUNCTION_ARGS) {
140                  }                  }
141                                    
142                  elog(INFO, "pgswish: check for swish-e error");                  elog(INFO, "pgswish: check for swish-e error");
143                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  error_or_abort( swish_handle );
144    
145                  /*                  /*
146                   * Prepare a values array for storage in our slot.                   * Prepare a values array for storage in our slot.
147                   * This should be an array of C strings which will                   * This should be an array of C strings which will
148                   * be processed later by the type input functions.                   * be processed later by the type input functions.
149                   */                   */
                 values = (char **) palloc(5 * sizeof(char *));  
150    
151                  sw_res = SwishNextResult( swish_results );                  sw_res = SwishNextResult( swish_results );
152                  if (! sw_res) {                  if (! sw_res) {
# Line 157  Datum pgswish(PG_FUNCTION_ARGS) { Line 154  Datum pgswish(PG_FUNCTION_ARGS) {
154                          SRF_RETURN_DONE(funcctx);                          SRF_RETURN_DONE(funcctx);
155                  }                  }
156                                    
157          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",
158              SwishResultPropertyStr   ( sw_res, "swishdocpath" ),                          SwishResultPropertyStr   ( sw_res, "swishdocpath" ),
159              SwishResultPropertyULong ( sw_res, "swishrank" ),                          SwishResultPropertyULong ( sw_res, "swishrank" ),
160              SwishResultPropertyULong ( sw_res, "swishdocsize" ),                          SwishResultPropertyULong ( sw_res, "swishdocsize" ),
161              SwishResultPropertyStr   ( sw_res, "swishtitle"),                          SwishResultPropertyStr   ( sw_res, "swishtitle"),
162              SwishResultPropertyStr   ( sw_res, "swishdbfile" ),                          SwishResultPropertyStr   ( sw_res, "swishdbfile" ),
163              SwishResultPropertyStr   ( sw_res, "swishlastmodified" ),                          SwishResultPropertyStr   ( sw_res, "swishlastmodified" ),
164              SwishResultPropertyULong ( sw_res, "swishreccount" ),  /* can figure this out in loop, of course */                          SwishResultPropertyULong ( sw_res, "swishreccount" ),  /* can figure this out in loop, of course */
165              SwishResultPropertyULong ( sw_res, "swishfilenum" )                          SwishResultPropertyULong ( sw_res, "swishfilenum" )
166          );                  );
167    
168                  elog(INFO, "pgswish: get prop");                  values = (char **) palloc(4 * sizeof(char *));
169                  prop = SwishResultPropertyStr ( sw_res, "swishdocpath" );  
170                  elog(INFO, "pgswish: got error?");                  values[0] = prop2int( sw_res, "swishrank" );
171                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  values[1] = prop2text( sw_res, "swishdocpath" );
172                  elog(INFO, "swishdocpath: %s", prop);                  values[2] = prop2text( sw_res, "swishtitle" );
173                    values[3] = prop2int( sw_res, "swishdocsize" );
 //              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" ) );  
174    
175    /*
176                    values[0] = (char *) palloc(16 * sizeof(char));
177                    snprintf(values[0], 16, "%d", 1);
178                    values[1] = (char *) palloc(16 * sizeof(char));
179                    snprintf(values[1], 16, "%d", 2);
180                    values[2] = (char *) palloc(16 * sizeof(char));
181                    snprintf(values[2], 16, "%d", 3);
182                    values[3] = (char *) palloc(16 * sizeof(char));
183                    snprintf(values[3], 16, "%d", 4);
184    */
185                    
186                  /* build a tuple */                  /* build a tuple */
187                  tuple = BuildTupleFromCStrings(attinmeta, values);                  tuple = BuildTupleFromCStrings(attinmeta, values);
188    
189                  /* make the tuple into a datum */                  /* make the tuple into a datum */
190                  result = TupleGetDatum(slot, tuple);                  result = TupleGetDatum(slot, tuple);
191    
192  }                  /* clean up ? */
193                  /* clean up (this is not really necessary) */                  pfree(values[0]);
194                    pfree(values[1]);
195                    pfree(values[2]);
196                    pfree(values[3]);
197                    pfree(values);
198                    
199                    elog(INFO, "row: %s|%s|%s|%s",values[0],values[1],values[2],values[3]);
200            
201                  SRF_RETURN_NEXT(funcctx, result);                  SRF_RETURN_NEXT(funcctx, result);
202          } else {          } else {
203                    elog(INFO, "loop over");
204    
205                  /* free swish object and close */                  /* free swish object and close */
206                  Free_Search_Object( search );                  Free_Search_Object( search );
207                  SwishClose( swish_handle );                  SwishClose( swish_handle );
# Line 208  if (0) { Line 216  if (0) {
216   *   *
217   */   */
218    
219    char *prop2text(SW_RESULT sw_res, char *propname) {
220            char *val;
221            char *prop;
222            int len;
223    
224            elog(INFO, "prop2text(%s)", propname);
225    
226            prop = SwishResultPropertyStr( sw_res, propname );
227            error_or_abort( swish_handle );
228    
229            len = strlen(prop);
230            elog(INFO, "prop2text(%s) = '%s' %d bytes", propname, prop, len);
231    
232            len++;
233            len *= sizeof(char);
234    
235            elog(INFO, "palloc(%d)", len);
236    
237            val = palloc(len);
238    
239            memset(val, 0, len);
240            strncpy(val, prop, len);
241    
242            elog(INFO, "val=%s", val);
243    
244            return val;
245    }
246    
247    char *prop2int(SW_RESULT sw_res, char *propname) {
248            char *val;
249            unsigned long prop;
250            int len;
251    
252            elog(INFO, "prop2int(%s)", propname);
253    
254            prop = SwishResultPropertyULong( sw_res, propname );
255            error_or_abort( swish_handle );
256    
257            elog(INFO, "prop2int(%s) = %lu", propname, prop);
258    
259            len = 128 * sizeof(char);
260            elog(INFO, "palloc(%d)", len);
261    
262            val = palloc(len);
263            memset(val, 0, len);
264    
265            snprintf(val, len, "%lu", prop);
266    
267            elog(INFO, "val=%s", val);
268    
269            return val;
270    }
271    
272    
273  static void error_or_abort( SW_HANDLE swish_handle ) {  static void error_or_abort( SW_HANDLE swish_handle ) {
274          if ( !SwishError( swish_handle ) )          if ( !SwishError( swish_handle ) )
275                  return;                  return;

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

  ViewVC Help
Powered by ViewVC 1.1.26