/[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 51 by dpavlin, Tue May 9 22:55:42 2006 UTC revision 57 by dpavlin, Thu May 11 16:19:38 2006 UTC
# Line 25  Line 25 
25  #include "funcapi.h"  #include "funcapi.h"
26  #include "utils/builtins.h"  #include "utils/builtins.h"
27  #include "utils/array.h"  #include "utils/array.h"
28    #include "utils/lsyscache.h"
29  #include "miscadmin.h"  #include "miscadmin.h"
30  #include <estraier.h>  #include <estraier.h>
31  #include <cabin.h>  #include <cabin.h>
# Line 41  Line 42 
42  #endif  #endif
43    
44  #define ATTR_DELIMITER "{{!}}"  #define ATTR_DELIMITER "{{!}}"
45    #define HINTS_PREFIX "HINTS."
46    
47  /* prototype */  /* prototype */
48  char *attr2text(ESTDOC *doc, char *attr);  char *attr2text(ESTDOC *doc, char *attr);
49  char *node_attr2text(ESTRESDOC *rdoc, char *attr);  char *node_attr2text(ESTRESDOC *rdoc, char *attr);
50    void cond_add_attr(ESTCOND *cond, char *attr);
51    
52    
53  /* work in progress */  /* work in progress */
# Line 77  Datum pgest_attr(PG_FUNCTION_ARGS) Line 80  Datum pgest_attr(PG_FUNCTION_ARGS)
80          ESTDB *db;          ESTDB *db;
81          ESTCOND *cond;          ESTCOND *cond;
82          ESTDOC *doc;          ESTDOC *doc;
         const CBLIST *texts;  
83          int ecode, *est_result, resnum;          int ecode, *est_result, resnum;
84          int limit = 0;          int limit = 0;
85          int offset = 0;          int offset = 0;
# Line 208  Datum pgest_attr(PG_FUNCTION_ARGS) Line 210  Datum pgest_attr(PG_FUNCTION_ARGS)
210          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
211          if (! PG_ARGISNULL(2) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(2) && strlen(attr) >= 10) {
212                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
213                  char *curr_attr;                  cond_add_attr(cond, attr);
                 curr_attr = strtok(attr, ATTR_DELIMITER);  
                 while (curr_attr) {  
                         elog(DEBUG1,"est_cond_add_attr(%s)", curr_attr);  
                         est_cond_add_attr(cond, curr_attr);  
                         curr_attr = strtok(NULL, ATTR_DELIMITER);  
                 }  
214          }          }
215    
216          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
# Line 323  char *attr2text(ESTDOC *doc, char *attr) Line 319  char *attr2text(ESTDOC *doc, char *attr)
319    
320          if (! doc) return (Datum) NULL;          if (! doc) return (Datum) NULL;
321    
322          elog(DEBUG1, "doc: %08x, attr: %s", doc, attr);          elog(DEBUG1, "doc: %p, attr: %s", doc, attr);
323    
324          if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) {          if ( (attrval = est_doc_attr(doc, attr)) && (attrlen = strlen(attrval)) ) {
325                  val = (char *) palloc(attrlen * sizeof(char));                  val = (char *) palloc(attrlen * sizeof(char));
# Line 399  Datum pgest_node(PG_FUNCTION_ARGS) Line 395  Datum pgest_node(PG_FUNCTION_ARGS)
395          ESTCOND *cond;          ESTCOND *cond;
396          ESTNODERES *nres;          ESTNODERES *nres;
397          ESTRESDOC *rdoc;          ESTRESDOC *rdoc;
398          const CBLIST *texts;          CBMAP *hints;
399          int resnum = 0;          int resnum = 0;
400          int limit = 0;          int limit = 0;
401          int offset = 0;          int offset = 0;
# Line 550  Datum pgest_node(PG_FUNCTION_ARGS) Line 546  Datum pgest_node(PG_FUNCTION_ARGS)
546          /* minimum valid attribute length is 10: @a STREQ a */          /* minimum valid attribute length is 10: @a STREQ a */
547          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {          if (! PG_ARGISNULL(_arg_attr) && strlen(attr) >= 10) {
548                  elog(DEBUG1,"attributes: %s", attr);                  elog(DEBUG1,"attributes: %s", attr);
549                  char *curr_attr;                  cond_add_attr(cond, attr);
                 curr_attr = strtok(attr, ATTR_DELIMITER);  
                 while (curr_attr) {  
                         elog(DEBUG1,"est_cond_add_attr(%s)", curr_attr);  
                         est_cond_add_attr(cond, curr_attr);  
                         curr_attr = strtok(NULL, ATTR_DELIMITER);  
                 }  
550          }          }
551    
552          /* set the search phrase to the search condition object */          /* set the search phrase to the search condition object */
# Line 602  Datum pgest_node(PG_FUNCTION_ARGS) Line 592  Datum pgest_node(PG_FUNCTION_ARGS)
592                  nrows = resnum - offset;                  nrows = resnum - offset;
593          }          }
594    
595            /* get hints */
596            hints = est_noderes_hints(nres);
597    
598          elog(DEBUG1, "pgest_node: found %d hits for %s", resnum, query);          elog(DEBUG1, "pgest_node: found %d hits for %s", resnum, query);
599    
600    
# Line 624  Datum pgest_node(PG_FUNCTION_ARGS) Line 617  Datum pgest_node(PG_FUNCTION_ARGS)
617                  for (j = 0; j < ncols; j++)                  for (j = 0; j < ncols; j++)
618                  {                  {
619                          bool    isnull;                          bool    isnull;
620                            char    *attr;  /* current attribute name */
621                            char    *hint;  /* position of current hint in attribute */
622                            char    *hint_val;
623    
624                          /* array value of this position */                          /* array value of this position */
625                          indx[0] = j + attr_dim_lower_bounds[0];                          indx[0] = j + attr_dim_lower_bounds[0];
626    
627                          dvalue = array_ref(attr_arr, attr_ndims, indx, -1, attr_len, attr_byval, attr_align, &isnull);                          dvalue = array_ref(attr_arr, attr_ndims, indx, -1, attr_len, attr_byval, attr_align, &isnull);
628                            attr = (char *)DirectFunctionCall1(textout, dvalue);
629    
630                          if (!isnull && rdoc)                          if (!isnull && (hint = strstr(attr, HINTS_PREFIX)) != NULL) {
631                                  values[j] = DatumGetCString(                                  /* skip HINTS. prefix */
632                                          node_attr2text(rdoc,                                  hint += strlen(HINTS_PREFIX);
633                                                  (char *)DirectFunctionCall1(textout, dvalue)  
634                                          ));                                  hint_val = cbmapget(hints, hint, -1, NULL);
635                                    elog(DEBUG2, "hint %s = %s", hint, hint_val);
636    
637                                    if (hint_val != NULL) {
638                                            values[j] = DatumGetCString( hint_val );
639                                    } else {
640                                            elog(INFO, "can't get hint in results: %s", hint);
641                                            values[j] = NULL;
642                                    }
643                            } else if (!isnull && rdoc)
644                                    values[j] = DatumGetCString( node_attr2text(rdoc, attr) );
645                          else                          else
646                                  values[j] = NULL;                                  values[j] = NULL;
647                  }                  }
# Line 683  char *node_attr2text(ESTRESDOC *rdoc, ch Line 690  char *node_attr2text(ESTRESDOC *rdoc, ch
690    
691          if (! rdoc) return (Datum) NULL;          if (! rdoc) return (Datum) NULL;
692    
693          elog(DEBUG1, "doc: %08x, attr: %s", rdoc, attr);          elog(DEBUG1, "doc: %p, attr: %s", rdoc, attr);
694    
695          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {          if ( (attrval = est_resdoc_attr(rdoc, attr)) && (attrlen = strlen(attrval)) ) {
696                  val = (char *) palloc(attrlen * sizeof(char));                  val = (char *) palloc(attrlen * sizeof(char));
# Line 709  char *node_attr2text(ESTRESDOC *rdoc, ch Line 716  char *node_attr2text(ESTRESDOC *rdoc, ch
716          return val;          return val;
717  }  }
718    
719    /* parse attributes and add them to confition */
720    void cond_add_attr(ESTCOND *cond, char *attr) {
721            char *next;
722            char *curr_attr;
723            while ( strlen(attr) > 0 ) {
724                    printf("len [%s] = %d\n", attr, strlen(attr));
725                    if ((next = strstr(attr, ATTR_DELIMITER)) != NULL) {
726                            curr_attr = palloc( next - attr + 1 );
727                            memcpy(curr_attr, attr, next-attr);
728                            curr_attr[next-attr] = '\0';
729                            next += strlen(ATTR_DELIMITER);
730                    } else {
731                            next = "";
732                            curr_attr = attr;
733                    }
734                    elog(DEBUG1, "est_cond_add_attr(%s)", curr_attr);
735                    est_cond_add_attr(cond, curr_attr);
736                    attr = next;
737            }
738    }

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

  ViewVC Help
Powered by ViewVC 1.1.26