/[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 44 by dpavlin, Sat Sep 10 22:51:03 2005 UTC revision 48 by dpavlin, Thu Oct 20 16:24:26 2005 UTC
# Line 246  Datum pgest_attr(PG_FUNCTION_ARGS) Line 246  Datum pgest_attr(PG_FUNCTION_ARGS)
246    
247          elog(DEBUG1, "pgest_attr: found %d hits for %s", resnum, query);          elog(DEBUG1, "pgest_attr: found %d hits for %s", resnum, query);
248    
   
249          values = (char **) palloc(ncols * sizeof(char *));          values = (char **) palloc(ncols * sizeof(char *));
250    
251          for (i = 0; i < nrows; i++)          for (i = 0; i < nrows; i++)
# Line 254  Datum pgest_attr(PG_FUNCTION_ARGS) Line 253  Datum pgest_attr(PG_FUNCTION_ARGS)
253    
254                  /* get result from estraier */                  /* get result from estraier */
255                  if (! ( doc = est_db_get_doc(db, est_result[i + offset], 0)) ) {                  if (! ( doc = est_db_get_doc(db, est_result[i + offset], 0)) ) {
256                          elog(INFO, "can't find result %d", i + offset);                          elog(INFO, "pgest_attr: can't find result %d", i + offset);
257                  } else {                  } else {
258                          elog(DEBUG1, "URI: %s\n Title: %s\n",                          elog(DEBUG1, "URI: %s\n Title: %s\n",
259                                  est_doc_attr(doc, "@uri"),                                  est_doc_attr(doc, "@uri"),
# Line 286  Datum pgest_attr(PG_FUNCTION_ARGS) Line 285  Datum pgest_attr(PG_FUNCTION_ARGS)
285                  /* now store it */                  /* now store it */
286                  tuplestore_puttuple(tupstore, tuple);                  tuplestore_puttuple(tupstore, tuple);
287    
   
288                  /* delete estraier document object */                  /* delete estraier document object */
289                  est_doc_delete(doc);                  if (doc) est_doc_delete(doc);
290          }          }
291    
292          tuplestore_donestoring(tupstore);          tuplestore_donestoring(tupstore);
# Line 323  char *attr2text(ESTDOC *doc, char *attr) Line 321  char *attr2text(ESTDOC *doc, char *attr)
321          int len;          int len;
322          int attrlen;          int attrlen;
323    
324            if (! doc) return (Datum) NULL;
325    
326          elog(DEBUG1, "doc: %08x, attr: %s", doc, attr);          elog(DEBUG1, "doc: %08x, attr: %s", doc, attr);
327    
328          if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) {          if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) {
# Line 355  char *attr2text(ESTDOC *doc, char *attr) Line 355  char *attr2text(ESTDOC *doc, char *attr)
355   *   *
356   */   */
357    
358    /* select * from pgest( */
359    #define _arg_node_uri 0
360    #define _arg_login 1
361    #define _arg_passwd 2
362    #define _arg_query 3
363    #define _arg_attr 4
364    #define _arg_order 5
365    #define _arg_limit 6
366    #define _arg_offset 7
367    #define _arg_attr_array 8
368    /* as (foo text, ... ); */
369    
370    
371  PG_FUNCTION_INFO_V1(pgest_node);  PG_FUNCTION_INFO_V1(pgest_node);
372  Datum pgest_node(PG_FUNCTION_ARGS)  Datum pgest_node(PG_FUNCTION_ARGS)
373  {  {
374          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(8);          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(_arg_attr_array);
375          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);
376          int             attr_ndims = ARR_NDIM(attr_arr);          int             attr_ndims = ARR_NDIM(attr_arr);
377          int             *attr_dim_counts = ARR_DIMS(attr_arr);          int             *attr_dim_counts = ARR_DIMS(attr_arr);
# Line 448  Datum pgest_node(PG_FUNCTION_ARGS) Line 461  Datum pgest_node(PG_FUNCTION_ARGS)
461          /* take rest of arguments from function */          /* take rest of arguments from function */
462    
463          /* node URL */          /* node URL */
464          if (PG_ARGISNULL(0)) {          if (PG_ARGISNULL(_arg_node_uri)) {
465                  ereport(ERROR,                  ereport(ERROR,
466                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
467                                   errmsg("node URL can't be null"),                                   errmsg("node URL can't be null"),
468                                   errdetail("Node URL must be valid URL to HyperEstraier node")));                                   errdetail("Node URL must be valid URL to HyperEstraier node")));
469          }          }
470          node_url = _textout(PG_GETARG_TEXT_P(0));          node_url = _textout(PG_GETARG_TEXT_P(_arg_node_uri));
471    
472          /* login and password */          /* login and password */
473          if (PG_ARGISNULL(1) || PG_ARGISNULL(2)) {          if (PG_ARGISNULL(_arg_login) || PG_ARGISNULL(_arg_passwd)) {
474                  ereport(ERROR,                  ereport(ERROR,
475                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
476                                   errmsg("username and password can't be NULL"),                                   errmsg("username and password can't be NULL"),
477                                   errdetail("You must specify valid username and password to HyperEstraier node")));                                   errdetail("You must specify valid username and password to HyperEstraier node")));
478          }          }
479          user = _textout(PG_GETARG_TEXT_P(1));          user = _textout(PG_GETARG_TEXT_P(_arg_login));
480          passwd = _textout(PG_GETARG_TEXT_P(2));          passwd = _textout(PG_GETARG_TEXT_P(_arg_passwd));
481    
482          /* query string */          /* query string */
483          if (PG_ARGISNULL(3)) {          if (PG_ARGISNULL(_arg_query)) {
484                  query = "";                  query = "";
485          } else {          } else {
486                  query = _textout(PG_GETARG_TEXT_P(3));                  query = _textout(PG_GETARG_TEXT_P(_arg_query));
487          }          }
488    
489          /* atribute filter */          /* atribute filter */
490          if (PG_ARGISNULL(4)) {          if (PG_ARGISNULL(_arg_attr)) {
491                  attr = "";                  attr = "";
492          } else {          } else {
493                  attr = _textout(PG_GETARG_TEXT_P(4));                  attr = _textout(PG_GETARG_TEXT_P(_arg_attr));
494          }          }
495                    
496          /* sort order */          /* sort order */
497          if (PG_ARGISNULL(5)) {          if (PG_ARGISNULL(_arg_order)) {
498                  order = "";                  order = "";
499          } else {          } else {
500                  order = _textout(PG_GETARG_TEXT_P(5));                  order = _textout(PG_GETARG_TEXT_P(_arg_order));
501          }          }
502    
503    
504          /* limit */          /* limit */
505          if (PG_ARGISNULL(6)) {          if (PG_ARGISNULL(_arg_limit)) {
506                  limit = 0;                  limit = 0;
507          } else {          } else {
508                  limit = PG_GETARG_INT32(6);                  limit = PG_GETARG_INT32(_arg_limit);
509          }          }
510    
511          /* offset */          /* offset */
512          if (PG_ARGISNULL(7)) {          if (PG_ARGISNULL(_arg_offset)) {
513                  offset = 0;                  offset = 0;
514          } else {          } else {
515                  offset = PG_GETARG_INT32(7);                  offset = PG_GETARG_INT32(_arg_offset);
516          }          }
517    
518          /* initialize the network environment */          /* initialize the network environment */
# Line 513  Datum pgest_node(PG_FUNCTION_ARGS) Line 526  Datum pgest_node(PG_FUNCTION_ARGS)
526          node = est_node_new(node_url);          node = est_node_new(node_url);
527          est_node_set_auth(node, user, passwd);          est_node_set_auth(node, user, passwd);
528    
529          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(4) ? "NULL" : attr), limit, offset);          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(_arg_attr) ? "NULL" : attr), limit, offset);
530                    
531          /* create a search condition object */          /* create a search condition object */
532          if (!(cond = est_cond_new())) {          if (!(cond = est_cond_new())) {
# Line 522  Datum pgest_node(PG_FUNCTION_ARGS) Line 535  Datum pgest_node(PG_FUNCTION_ARGS)
535          }          }
536                    
537          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
538          if (! PG_ARGISNULL(3) && strlen(query) > 0)          if (! PG_ARGISNULL(_arg_query) && strlen(query) > 0)
539                  est_cond_set_phrase(cond, query);                  est_cond_set_phrase(cond, query);
540    
541          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
542          if (! PG_ARGISNULL(4) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {
543                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
544                  char *curr_attr;                  char *curr_attr;
545                  curr_attr = strtok(attr, ATTR_DELIMITER);                  curr_attr = strtok(attr, ATTR_DELIMITER);
# Line 538  Datum pgest_node(PG_FUNCTION_ARGS) Line 551  Datum pgest_node(PG_FUNCTION_ARGS)
551          }          }
552    
553          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
554          if (! PG_ARGISNULL(5) && strlen(order) > 0) {          if (! PG_ARGISNULL(_arg_order) && strlen(order) > 0) {
555                  elog(DEBUG1,"est_cond_set_order(%s)", order);                  elog(DEBUG1,"est_cond_set_order(%s)", order);
556                  est_cond_set_order(cond, order);                  est_cond_set_order(cond, order);
557          }          }
# Line 587  Datum pgest_node(PG_FUNCTION_ARGS) Line 600  Datum pgest_node(PG_FUNCTION_ARGS)
600    
601                  /* get result from estraier */                  /* get result from estraier */
602                  if (! ( rdoc = est_noderes_get_doc(nres, i + offset) )) {                  if (! ( rdoc = est_noderes_get_doc(nres, i + offset) )) {
603                          elog(INFO, "can't find result %d", i + offset);                          elog(INFO, "pgest_node: can't find result %d", i + offset);
604                  } else {                  } else {
605                          elog(DEBUG1, "URI: %s\n Title: %s\n",                          elog(DEBUG1, "URI: %s\n Title: %s\n",
606                                  est_resdoc_attr(rdoc, "@uri"),                                  est_resdoc_attr(rdoc, "@uri"),
# Line 656  char *node_attr2text(ESTRESDOC *rdoc, ch Line 669  char *node_attr2text(ESTRESDOC *rdoc, ch
669          int len;          int len;
670          int attrlen;          int attrlen;
671    
672            if (! rdoc) return (Datum) NULL;
673    
674          elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr);          elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr);
675    
676          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {

Legend:
Removed from v.44  
changed lines
  Added in v.48

  ViewVC Help
Powered by ViewVC 1.1.26