/[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 41 by dpavlin, Sat Sep 10 20:35:09 2005 UTC revision 51 by dpavlin, Tue May 9 22:55:42 2006 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_depth 3
363    #define _arg_query 4
364    #define _arg_attr 5
365    #define _arg_order 6
366    #define _arg_limit 7
367    #define _arg_offset 8
368    #define _arg_attr_array 9
369    /* as (foo text, ... ); */
370    
371    
372  PG_FUNCTION_INFO_V1(pgest_node);  PG_FUNCTION_INFO_V1(pgest_node);
373  Datum pgest_node(PG_FUNCTION_ARGS)  Datum pgest_node(PG_FUNCTION_ARGS)
374  {  {
375          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(8);          ArrayType       *attr_arr = PG_GETARG_ARRAYTYPE_P(_arg_attr_array);
376          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);          Oid             attr_element_type = ARR_ELEMTYPE(attr_arr);
377          int             attr_ndims = ARR_NDIM(attr_arr);          int             attr_ndims = ARR_NDIM(attr_arr);
378          int             *attr_dim_counts = ARR_DIMS(attr_arr);          int             *attr_dim_counts = ARR_DIMS(attr_arr);
# Line 389  Datum pgest_node(PG_FUNCTION_ARGS) Line 403  Datum pgest_node(PG_FUNCTION_ARGS)
403          int resnum = 0;          int resnum = 0;
404          int limit = 0;          int limit = 0;
405          int offset = 0;          int offset = 0;
406            int depth = 0;
407    
408          char            *node_url;          char            *node_url;
409          char            *user, *passwd;          char            *user, *passwd;
# Line 448  Datum pgest_node(PG_FUNCTION_ARGS) Line 463  Datum pgest_node(PG_FUNCTION_ARGS)
463          /* take rest of arguments from function */          /* take rest of arguments from function */
464    
465          /* node URL */          /* node URL */
466          if (PG_ARGISNULL(0)) {          if (PG_ARGISNULL(_arg_node_uri)) {
467                  ereport(ERROR,                  ereport(ERROR,
468                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
469                                   errmsg("node URL can't be null"),                                   errmsg("node URL can't be null"),
470                                   errdetail("Node URL must be valid URL to HyperEstraier node")));                                   errdetail("Node URL must be valid URL to HyperEstraier node")));
471          }          }
472          node_url = _textout(PG_GETARG_TEXT_P(0));          node_url = _textout(PG_GETARG_TEXT_P(_arg_node_uri));
473    
474          /* login and password */          /* login and password */
475          if (PG_ARGISNULL(1) || PG_ARGISNULL(2)) {          if (PG_ARGISNULL(_arg_login) || PG_ARGISNULL(_arg_passwd)) {
476                  ereport(ERROR,                  ereport(ERROR,
477                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
478                                   errmsg("username and password can't be NULL"),                                   errmsg("username and password can't be NULL"),
479                                   errdetail("You must specify valid username and password to HyperEstraier node")));                                   errdetail("You must specify valid username and password to HyperEstraier node")));
480          }          }
481          user = _textout(PG_GETARG_TEXT_P(1));          user = _textout(PG_GETARG_TEXT_P(_arg_login));
482          passwd = _textout(PG_GETARG_TEXT_P(2));          passwd = _textout(PG_GETARG_TEXT_P(_arg_passwd));
483    
484            /* depth of search */
485            if (PG_ARGISNULL(_arg_depth)) {
486                    depth = 0;
487            } else {
488                    depth = PG_GETARG_INT32(_arg_depth);
489            }
490    
491          /* query string */          /* query string */
492          if (PG_ARGISNULL(3)) {          if (PG_ARGISNULL(_arg_query)) {
493                  query = "";                  query = "";
494          } else {          } else {
495                  query = _textout(PG_GETARG_TEXT_P(3));                  query = _textout(PG_GETARG_TEXT_P(_arg_query));
496          }          }
497    
498          /* atribute filter */          /* atribute filter */
499          if (PG_ARGISNULL(4)) {          if (PG_ARGISNULL(_arg_attr)) {
500                  attr = "";                  attr = "";
501          } else {          } else {
502                  attr = _textout(PG_GETARG_TEXT_P(4));                  attr = _textout(PG_GETARG_TEXT_P(_arg_attr));
503          }          }
504                    
505          /* sort order */          /* sort order */
506          if (PG_ARGISNULL(5)) {          if (PG_ARGISNULL(_arg_order)) {
507                  order = "";                  order = "";
508          } else {          } else {
509                  order = _textout(PG_GETARG_TEXT_P(5));                  order = _textout(PG_GETARG_TEXT_P(_arg_order));
510          }          }
511    
512    
513          /* limit */          /* limit */
514          if (PG_ARGISNULL(6)) {          if (PG_ARGISNULL(_arg_limit)) {
515                  limit = 0;                  limit = 0;
516          } else {          } else {
517                  limit = PG_GETARG_INT32(6);                  limit = PG_GETARG_INT32(_arg_limit);
518          }          }
519    
520          /* offset */          /* offset */
521          if (PG_ARGISNULL(7)) {          if (PG_ARGISNULL(_arg_offset)) {
522                  offset = 0;                  offset = 0;
523          } else {          } else {
524                  offset = PG_GETARG_INT32(7);                  offset = PG_GETARG_INT32(_arg_offset);
525          }          }
526    
527          /* initialize the network environment */          /* initialize the network environment */
# Line 513  Datum pgest_node(PG_FUNCTION_ARGS) Line 535  Datum pgest_node(PG_FUNCTION_ARGS)
535          node = est_node_new(node_url);          node = est_node_new(node_url);
536          est_node_set_auth(node, user, passwd);          est_node_set_auth(node, user, passwd);
537    
538          elog(DEBUG1, "pgest_node: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(4) ? "NULL" : attr), limit, offset);          elog(DEBUG1, "pgest_node: node: %s (d:%d) query[%s] attr[%s] limit %d offset %d", node_url, depth, query, (PG_ARGISNULL(_arg_attr) ? "NULL" : attr), limit, offset);
539                    
540          /* create a search condition object */          /* create a search condition object */
541          if (!(cond = est_cond_new())) {          if (!(cond = est_cond_new())) {
# Line 522  Datum pgest_node(PG_FUNCTION_ARGS) Line 544  Datum pgest_node(PG_FUNCTION_ARGS)
544          }          }
545                    
546          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
547          if (! PG_ARGISNULL(3) && strlen(query) > 0)          if (! PG_ARGISNULL(_arg_query) && strlen(query) > 0)
548                  est_cond_set_phrase(cond, query);                  est_cond_set_phrase(cond, query);
549    
550          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
551          if (! PG_ARGISNULL(4) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {
552                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
553                  char *curr_attr;                  char *curr_attr;
554                  curr_attr = strtok(attr, ATTR_DELIMITER);                  curr_attr = strtok(attr, ATTR_DELIMITER);
# Line 538  Datum pgest_node(PG_FUNCTION_ARGS) Line 560  Datum pgest_node(PG_FUNCTION_ARGS)
560          }          }
561    
562          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
563          if (! PG_ARGISNULL(5) && strlen(order) > 0) {          if (! PG_ARGISNULL(_arg_order) && strlen(order) > 0) {
564                  elog(DEBUG1,"est_cond_set_order(%s)", order);                  elog(DEBUG1,"est_cond_set_order(%s)", order);
565                  est_cond_set_order(cond, order);                  est_cond_set_order(cond, order);
566          }          }
# Line 548  Datum pgest_node(PG_FUNCTION_ARGS) Line 570  Datum pgest_node(PG_FUNCTION_ARGS)
570                  est_cond_set_max(cond, limit + offset);                  est_cond_set_max(cond, limit + offset);
571          }          }
572    
573            if (offset) {
574                    elog(DEBUG1,"est_cond_set_skip(%d)", offset);
575                    est_cond_set_skip(cond, offset);
576            }
577    
578          /* get the result of search */          /* get the result of search */
579          /* FIXME: allow user to specify depath of search */          nres = est_node_search(node, cond, depth);
580          nres = est_node_search(node, cond, 0);  
581            if (! nres) {
582                    int status = est_node_status(node);
583                    est_cond_delete(cond);
584                    est_node_delete(node);
585                    est_free_net_env();
586                    ereport(ERROR, (errcode(ERRCODE_QUERY_CANCELED),
587                            errmsg("pgest_node: search failed, node status %d", status)));
588            }
589    
590          /* get number of results */          /* get number of results */
591          resnum = est_noderes_doc_num(nres);          resnum = est_noderes_doc_num(nres);
# Line 567  Datum pgest_node(PG_FUNCTION_ARGS) Line 602  Datum pgest_node(PG_FUNCTION_ARGS)
602                  nrows = resnum - offset;                  nrows = resnum - offset;
603          }          }
604    
   
605          elog(DEBUG1, "pgest_node: found %d hits for %s", resnum, query);          elog(DEBUG1, "pgest_node: found %d hits for %s", resnum, query);
606    
607    
# Line 577  Datum pgest_node(PG_FUNCTION_ARGS) Line 611  Datum pgest_node(PG_FUNCTION_ARGS)
611          {          {
612    
613                  /* get result from estraier */                  /* get result from estraier */
614                  if (! ( rdoc = est_noderes_get_doc(nres, i + offset) )) {                  if (! ( rdoc = est_noderes_get_doc(nres, i) )) {
615                          elog(INFO, "can't find result %d", i + offset);                          elog(INFO, "pgest_node: can't find result %d", i + offset);
616                  } else {                  } else {
617                          elog(DEBUG1, "URI: %s\n Title: %s\n",                          elog(DEBUG1, "URI: %s\n Title: %s\n",
618                                  est_resdoc_attr(rdoc, "@uri"),                                  est_resdoc_attr(rdoc, "@uri"),
# Line 647  char *node_attr2text(ESTRESDOC *rdoc, ch Line 681  char *node_attr2text(ESTRESDOC *rdoc, ch
681          int len;          int len;
682          int attrlen;          int attrlen;
683    
684            if (! rdoc) return (Datum) NULL;
685    
686          elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr);          elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr);
687    
688          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {

Legend:
Removed from v.41  
changed lines
  Added in v.51

  ViewVC Help
Powered by ViewVC 1.1.26