/[pgestraier]/trunk/pgest.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/pgest.c

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

revision 1 by dpavlin, Fri May 20 12:19:05 2005 UTC revision 4 by dpavlin, Fri May 20 18:45:01 2005 UTC
# Line 40  ESTCOND *cond; Line 40  ESTCOND *cond;
40  ESTDOC *doc;  ESTDOC *doc;
41  const CBLIST *texts;  const CBLIST *texts;
42  int ecode, *est_result, resnum, i, j;  int ecode, *est_result, resnum, i, j;
43    int limit = 0;
44    int offset = 0;
45    
46  /* define PostgreSQL v1 function */  /* define PostgreSQL v1 function */
47  PG_FUNCTION_INFO_V1(pgest);  PG_FUNCTION_INFO_V1(pgest);
# Line 62  Datum pgest(PG_FUNCTION_ARGS) { Line 64  Datum pgest(PG_FUNCTION_ARGS) {
64                  //index_path = _textout(PG_GETARG_TEXT_P(0));                  //index_path = _textout(PG_GETARG_TEXT_P(0));
65                  index_path = _textout(PG_GETARG_TEXT_P(0));                  index_path = _textout(PG_GETARG_TEXT_P(0));
66                  query = _textout(PG_GETARG_TEXT_P(1));                  query = _textout(PG_GETARG_TEXT_P(1));
67                    limit = PG_GETARG_INT32(2);
68                    offset = PG_GETARG_INT32(3);
69    
70                  /* create a function context for cross-call persistence */                  /* create a function context for cross-call persistence */
71                  funcctx = SRF_FIRSTCALL_INIT();                  funcctx = SRF_FIRSTCALL_INIT();
# Line 77  Datum pgest(PG_FUNCTION_ARGS) { Line 81  Datum pgest(PG_FUNCTION_ARGS) {
81                          SRF_RETURN_DONE(funcctx);                          SRF_RETURN_DONE(funcctx);
82                  }                  }
83                                    
84                  elog(DEBUG2, "pgest: query=%s", query);                  elog(INFO, "pgest: query=%s limit %d offset %d", query, limit, offset);
85                                    
86                  /* create a search condition object */                  /* create a search condition object */
87                  if (!(cond = est_cond_new())) {                  if (!(cond = est_cond_new())) {
# Line 98  Datum pgest(PG_FUNCTION_ARGS) { Line 102  Datum pgest(PG_FUNCTION_ARGS) {
102                  if ( 0 == funcctx->max_calls )                  if ( 0 == funcctx->max_calls )
103                          elog(INFO, "pgest: no results for: %s", query );                          elog(INFO, "pgest: no results for: %s", query );
104    
105                  elog(INFO, "pgest: found %d hits for %s", funcctx->max_calls, query);                  elog(DEBUG1, "pgest: found %d hits for %s", funcctx->max_calls, query);
106    
107                  /* Build a tuple description for a __pgest tuple */                  /* Build a tuple description for a __pgest tuple */
108                  tupdesc = RelationNameGetTupleDesc("__pgest");                  tupdesc = RelationNameGetTupleDesc("__pgest");
# Line 118  Datum pgest(PG_FUNCTION_ARGS) { Line 122  Datum pgest(PG_FUNCTION_ARGS) {
122    
123                  MemoryContextSwitchTo(oldcontext);                  MemoryContextSwitchTo(oldcontext);
124    
125                  elog(INFO, "SRF_IS_FIRSTCALL done");                  elog(DEBUG1, "SRF_IS_FIRSTCALL done");
126          }          }
127    
128          /* stuff done on every call of the function */          /* stuff done on every call of the function */
# Line 128  Datum pgest(PG_FUNCTION_ARGS) { Line 132  Datum pgest(PG_FUNCTION_ARGS) {
132          max_calls = funcctx->max_calls;          max_calls = funcctx->max_calls;
133          slot = funcctx->slot;          slot = funcctx->slot;
134          attinmeta = funcctx->attinmeta;          attinmeta = funcctx->attinmeta;
135    
136            if (limit && call_cntr > limit - 1) {
137                    elog(INFO, "call_cntr: %d limit: %d", call_cntr, limit);
138                    SRF_RETURN_DONE(funcctx);
139            }
140    
141          if (call_cntr < max_calls) {          if (call_cntr < max_calls) {
142                  char            **values;                  char            **values;
143                  HeapTuple       tuple;                  HeapTuple       tuple;
144                  Datum           result;                  Datum           result;
145    
146                  elog(INFO, "pgest: loop count %d", call_cntr);                  elog(DEBUG1, "pgest: loop count %d", call_cntr);
147    
148                  if (! est_result) {                  if (! est_result) {
149                          elog(ERROR, "pgest: no estraier results");                          elog(ERROR, "pgest: no estraier results");
# Line 147  Datum pgest(PG_FUNCTION_ARGS) { Line 156  Datum pgest(PG_FUNCTION_ARGS) {
156                   * be processed later by the type input functions.                   * be processed later by the type input functions.
157                   */                   */
158    
159                  if (doc = est_db_get_doc(db, est_result[call_cntr], 0)) {                  if (doc = est_db_get_doc(db, est_result[call_cntr + offset], 0)) {
160                                    
161                          elog(INFO, "URI: %s\n Title: %s\n",                          elog(DEBUG1, "URI: %s\n Title: %s\n",
162                                  est_doc_attr(doc, "@uri"),                                  est_doc_attr(doc, "@uri"),
163                                  est_doc_attr(doc, "@title")                                  est_doc_attr(doc, "@title")
164                          );                          );
# Line 197  Datum pgest(PG_FUNCTION_ARGS) { Line 206  Datum pgest(PG_FUNCTION_ARGS) {
206                    
207                  SRF_RETURN_NEXT(funcctx, result);                  SRF_RETURN_NEXT(funcctx, result);
208          } else {          } else {
209                  elog(INFO, "loop over");                  elog(DEBUG1, "loop over");
210    
211                  if(!est_db_close(db, &ecode)){                  if(!est_db_close(db, &ecode)){
212                          elog(INFO, "est_db_close error: %s", est_err_msg(ecode));                          elog(INFO, "est_db_close error: %s", est_err_msg(ecode));
# Line 292  char *attr2text(ESTDOC *doc, char *attr) Line 301  char *attr2text(ESTDOC *doc, char *attr)
301          char *val;          char *val;
302          const char *attrval;          const char *attrval;
303          int len;          int len;
304            int attrlen;
305    
306          elog(INFO, "doc: %08x, attr: %s", doc, attr);          elog(DEBUG1, "doc: %08x, attr: %s", doc, attr);
307    
308          if (attrval = est_doc_attr(doc, attr)) {          if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) {
309                  val = (char *) palloc(strlen(attrval) * sizeof(char));                  val = (char *) palloc(attrlen * sizeof(char));
310          } else {          } else {
311                  return (Datum) NULL;                  return (Datum) NULL;
312          }          }
313    
314          len = strlen(attrval);          len = strlen(attrval);
315          elog(INFO, "attr2text(%s) = '%s' %d bytes", attr, attrval, len);          elog(DEBUG1, "attr2text(%s) = '%s' %d bytes", attr, attrval, len);
316    
317          len++;          len++;
318          len *= sizeof(char);          len *= sizeof(char);

Legend:
Removed from v.1  
changed lines
  Added in v.4

  ViewVC Help
Powered by ViewVC 1.1.26