/[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 10 by dpavlin, Sat Feb 19 11:39:11 2005 UTC revision 11 by dpavlin, Sat Feb 19 12:27:04 2005 UTC
# Line 29  Line 29 
29    
30  #define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))  #define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
31  #define _textout(str) DatumGetPointer(DirectFunctionCall1(textout, PointerGetDatum(str)))  #define _textout(str) DatumGetPointer(DirectFunctionCall1(textout, PointerGetDatum(str)))
32    #define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp)))
33    #define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
34    
35    
36  SW_HANDLE   swish_handle = NULL;/* Database handle */  SW_HANDLE   swish_handle = NULL;/* Database handle */
37  SW_SEARCH   search = NULL;      /* search handle -- holds search parameters */  SW_SEARCH   search = NULL;      /* search handle -- holds search parameters */
38  SW_RESULTS  results = NULL;     /* results handle -- holds list of results */  SW_RESULTS  swish_results = NULL;       /* results handle -- holds list of results */
39    
40  /* define PostgreSQL v1 function */  /* define PostgreSQL v1 function */
41  PG_FUNCTION_INFO_V1(pgswish);  PG_FUNCTION_INFO_V1(pgswish);
# Line 45  Datum pgswish(PG_FUNCTION_ARGS) { Line 47  Datum pgswish(PG_FUNCTION_ARGS) {
47          TupleDesc       tupdesc;          TupleDesc       tupdesc;
48          TupleTableSlot  *slot;          TupleTableSlot  *slot;
49          AttInMetadata   *attinmeta;          AttInMetadata   *attinmeta;
         SW_HANDLE       swish_handle = NULL;    /* Database handle */  
         SW_SEARCH       search = NULL;          /* search handle -- holds search parameters */  
         SW_RESULTS      results = NULL;         /* results handle -- holds list of results */  
50          char            *index_path;          char            *index_path;
51          char            *query;          char            *query;
52    
# Line 89  Datum pgswish(PG_FUNCTION_ARGS) { Line 88  Datum pgswish(PG_FUNCTION_ARGS) {
88    
89                  elog(INFO, "pgswish: SwishQuery(%s)", query);                  elog(INFO, "pgswish: SwishQuery(%s)", query);
90                  /* 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 */
91                  results = SwishQuery( swish_handle, query);                  swish_results = SwishQuery( swish_handle, query);
92                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );                  if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );
93    
94                  /* total number of tuples to be returned */                  /* total number of tuples to be returned */
95                  funcctx->max_calls = SwishHits( results );                  funcctx->max_calls = SwishHits( swish_results );
96    
97                  /* check if results exists */                  /* check if results exists */
98                  if ( 0 == funcctx->max_calls )                  if ( 0 == funcctx->max_calls )
# Line 132  Datum pgswish(PG_FUNCTION_ARGS) { Line 131  Datum pgswish(PG_FUNCTION_ARGS) {
131                  char            **values;                  char            **values;
132                  HeapTuple       tuple;                  HeapTuple       tuple;
133                  Datum           result;                  Datum           result;
134                    char            *prop;
135                    SW_RESULT       *sw_res;        /* one row from swish-e results */
136    
137                    elog(INFO, "pgswish: in loop %d", call_cntr);
138    
139                    if (! swish_results) {
140                            elog(ERROR, "pgswish: no swish-e results");
141                            SRF_RETURN_DONE(funcctx);
142                    }
143                    
144                    elog(INFO, "pgswish: check for swish-e error");
145                    if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );
146    
 if (0) {  
147                  /*                  /*
148                   * Prepare a values array for storage in our slot.                   * Prepare a values array for storage in our slot.
149                   * This should be an array of C strings which will                   * This should be an array of C strings which will
150                   * be processed later by the type input functions.                   * be processed later by the type input functions.
151                   */                   */
152                  values = (char **) palloc(5 * sizeof(char *));                  values = (char **) palloc(5 * sizeof(char *));
153                  values[0] = _textout( SwishResultPropertyULong ( result, "swishrank" ) );  
154                  values[1] = _textout( SwishResultPropertyStr   ( result, "swishdocpath" ) );                  sw_res = SwishNextResult( swish_results );
155                  values[2] = _textout( SwishResultPropertyStr   ( result, "swishtitle" ) );                  if (! sw_res) {
156                  values[3] = _textout( SwishResultPropertyStr   ( result, "swishdocsize" ) );                          elog(ERROR, "pgswish: swish-e sort result list: %d rows expected %d", call_cntr, max_calls - 1);
157                  values[4] = _textout( SwishResultPropertyStr   ( result, "swishdbfile" ) );                          SRF_RETURN_DONE(funcctx);
158                    }
159                    
160            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",
161                SwishResultPropertyStr   ( sw_res, "swishdocpath" ),
162                SwishResultPropertyULong ( sw_res, "swishrank" ),
163                SwishResultPropertyULong ( sw_res, "swishdocsize" ),
164                SwishResultPropertyStr   ( sw_res, "swishtitle"),
165                SwishResultPropertyStr   ( sw_res, "swishdbfile" ),
166                SwishResultPropertyStr   ( sw_res, "swishlastmodified" ),
167                SwishResultPropertyULong ( sw_res, "swishreccount" ),  /* can figure this out in loop, of course */
168                SwishResultPropertyULong ( sw_res, "swishfilenum" )
169            );
170    
171                    elog(INFO, "pgswish: get prop");
172                    prop = SwishResultPropertyStr ( sw_res, "swishdocpath" );
173                    elog(INFO, "pgswish: got error?");
174                    if ( SwishError( swish_handle ) ) error_or_abort( swish_handle );
175                    elog(INFO, "swishdocpath: %s", prop);
176    
177    //              values[0] = GET_STR( SwishResultPropertyULong ( sw_res, "swishrank" ) );
178                    values[0] = NULL;
179    //              values[1] = GET_TEXT( SwishResultPropertyStr   ( sw_res, "swishdocpath" ) );
180    if (0) {
181                    values[1] = GET_TEXT( SwishResultPropertyStr   ( sw_res, "swishdocpath" ) );
182                    values[2] = _textout( SwishResultPropertyStr   ( sw_res, "swishtitle" ) );
183                    values[3] = _textout( SwishResultPropertyStr   ( sw_res, "swishdocsize" ) );
184                    values[4] = _textout( SwishResultPropertyStr   ( sw_res, "swishdbfile" ) );
185    
186                  /* build a tuple */                  /* build a tuple */
187                  tuple = BuildTupleFromCStrings(attinmeta, values);                  tuple = BuildTupleFromCStrings(attinmeta, values);

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

  ViewVC Help
Powered by ViewVC 1.1.26