X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=recctrl%2Frecgrs.c;h=9b6cc843b19d981ef2f1215365003022239fc8d2;hb=b385fad64ec1afb51fd0ec9ad76567282ab20bfe;hp=4f3ab503291a0f8b2cc28eaf8575a532663acbc4;hpb=b17cf6fd6cad7283033afe18fc346250ec1b2ad3;p=idzebra-moved-to-github.git diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index 4f3ab50..9b6cc84 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -1,5 +1,5 @@ -/* $Id: recgrs.c,v 1.71 2002-12-16 20:27:18 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 +/* $Id: recgrs.c,v 1.76 2003-04-24 19:34:19 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps This file is part of the Zebra server. @@ -123,6 +123,71 @@ static void grs_destroy(void *clientData) xfree (h); } +int d1_check_xpath_predicate(data1_node *n, struct xpath_predicate *p) { + int res = 1; + char *attname; + data1_xattr *attr; + + if (!p) { + return (1); + } else { + if (p->which == XPATH_PREDICATE_RELATION) { + if (p->u.relation.name[0]) { + if (*p->u.relation.name != '@') { + logf(LOG_WARN, + " Only attributes (@) are supported in xelm xpath predicates"); + logf(LOG_WARN, "predicate %s ignored", p->u.relation.name); + return (1); + } + attname = p->u.relation.name + 1; + res = 0; + /* looking for the attribute with a specified name */ + for (attr = n->u.tag.attributes; attr; attr = attr->next) { + logf(LOG_DEBUG," - attribute %s <-> %s", attname, attr->name ); + + if (!strcmp(attr->name, attname)) { + if (p->u.relation.op[0]) { + if (*p->u.relation.op != '=') { + logf(LOG_WARN, + "Only '=' relation is supported (%s)",p->u.relation.op); + logf(LOG_WARN, "predicate %s ignored", p->u.relation.name); + res = 1; break; + } else { + logf(LOG_DEBUG," - value %s <-> %s", + p->u.relation.value, attr->value ); + if (!strcmp(attr->value, p->u.relation.value)) { + res = 1; break; + } + } + } else { + /* attribute exists, no value specified */ + res = 1; break; + } + } + } + return (res); + } else { + return (1); + } + } + else if (p->which == XPATH_PREDICATE_BOOLEAN) { + if (!strcmp(p->u.boolean.op,"and")) { + return (d1_check_xpath_predicate(n, p->u.boolean.left) + && d1_check_xpath_predicate(n, p->u.boolean.right)); + } + else if (!strcmp(p->u.boolean.op,"or")) { + return (d1_check_xpath_predicate(n, p->u.boolean.left) + || d1_check_xpath_predicate(n, p->u.boolean.right)); + } else { + logf(LOG_WARN, "Unknown boolean relation %s, ignored",p->u.boolean.op); + return (1); + } + } + } + return 0; +} + + /* *ostrich* New function, looking for xpath "element" definitions in abs, by @@ -131,13 +196,25 @@ static void grs_destroy(void *clientData) against the given tagpath. The first matching entry is returned. pop, 2002-12-13 + + Added support for enhanced xelm. Now [] predicates are considered + as well, when selecting indexing rules... (why the hell it's called + termlist???) + + pop, 2003-01-17 + */ data1_termlist *xpath_termlist_by_tagpath(char *tagpath, data1_node *n) { data1_absyn *abs = n->root->u.root.absyn; data1_xpelement *xpe = abs->xp_elements; - char *pexpr = malloc(strlen(tagpath)+2); + data1_node *nn; +#ifdef ENHANCED_XELM + struct xpath_location_step *xp; + +#endif + char *pexpr = xmalloc(strlen(tagpath)+2); int ok = 0; sprintf (pexpr, "%s\n", tagpath); @@ -168,11 +245,45 @@ data1_termlist *xpath_termlist_by_tagpath(char *tagpath, data1_node *n) } while (i >= 0); } pexpr--; - if (ok) break; + if (ok) { +#ifdef ENHANCED_XELM + /* we have to check the perdicates up to the root node */ + xp = xpe->xpath; + + /* find the first tag up in the node structure */ + nn = n; while (nn && nn->which != DATA1N_tag) { + nn = nn->parent; + } + + /* go from inside out in the node structure, while going + backwards trough xpath location steps ... */ + for (i=xpe->xpath_len - 1; i>0; i--) { + + logf(LOG_DEBUG,"Checking step %d: %s on tag %s", + i,xp[i].part,nn->u.tag.tag); + + if (!d1_check_xpath_predicate(nn, xp[i].predicate)) { + logf(LOG_DEBUG," Predicates didn't match"); + ok = 0; + break; + } + + if (nn->which == DATA1N_tag) { + nn = nn->parent; + } + } +#endif + if (ok) { + break; + } + } xpe = xpe->next; } + + xfree(pexpr); if (ok) { + logf(LOG_DEBUG,"Got it"); return xpe->termlists; } else { return NULL; @@ -237,7 +348,7 @@ static void index_xpath (data1_node *n, struct recExtractCtrl *p, tag_path_full[flen] = 0; /* If we have a matching termlist... */ - if (tl = xpath_termlist_by_tagpath(tag_path_full, n)) { + if ((tl = xpath_termlist_by_tagpath(tag_path_full, n))) { for (; tl; tl = tl->next) { wrd->reg_type = *tl->structure; /* this is the ! case, so structure is for the xpath index */ @@ -354,8 +465,8 @@ static void index_xpath (data1_node *n, struct recExtractCtrl *p, wrd->length = strlen(xp->value); wrd->reg_type = 'w'; - if (tl = xpath_termlist_by_tagpath(attr_tag_path_full, - n)) { + if ((tl = xpath_termlist_by_tagpath(attr_tag_path_full, + n))) { for (; tl; tl = tl->next) { wrd->reg_type = *tl->structure; if (!tl->att) { @@ -452,10 +563,10 @@ static void index_termlist (data1_node *par, data1_node *n, tlist->att->name, tlist->att->value, tlist->source); printf (" data=\""); - for (i = 0; ilength && i < 8; i++) + for (i = 0; ilength && i < 40; i++) fputc (wrd->string[i], stdout); fputc ('"', stdout); - if (wrd->length > 8) + if (wrd->length > 40) printf (" ..."); fputc ('\n', stdout); } @@ -859,14 +970,25 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) #if 0 data1_pr_tree (p->dh, node, stdout); #endif +#if YAZ_VERSIONL >= 0x010903L if (p->comp && p->comp->which == Z_RecordComp_complex && p->comp->u.complex->generic && - p->comp->u.complex->generic->schema) + p->comp->u.complex->generic->which == Z_Schema_oid && + p->comp->u.complex->generic->schema.oid) + { + oident *oe = oid_getentbyoid (p->comp->u.complex->generic->schema.oid); + if (oe) + requested_schema = oe->value; + } +#else + if (p->comp && p->comp->which == Z_RecordComp_complex && + p->comp->u.complex->generic && p->comp->u.complex->generic->schema) { oident *oe = oid_getentbyoid (p->comp->u.complex->generic->schema); if (oe) requested_schema = oe->value; } +#endif /* If schema has been specified, map if possible, then check that * we got the right one