X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=recctrl%2Frecgrs.c;h=57b144bcaaf7e9dba836c7cc6561071a13f2214c;hp=8e60bf0ef9f137e8733c7bf441d9e459ac021c25;hb=7e75317bed8eecabcb57e59b16093a32238738e2;hpb=1ccf2613ceef2359f589cb3dd7e72a899c618b2f diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index 8e60bf0..57b144b 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -1,10 +1,29 @@ /* - * Copyright (C) 1994-2000, Index Data + * Copyright (C) 1994-2001, Index Data * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss * * $Log: recgrs.c,v $ - * Revision 1.36 2000-12-05 10:01:44 adam + * Revision 1.42 2002-02-20 17:30:01 adam + * Work on new API. Locking system re-implemented + * + * Revision 1.41 2001/05/22 21:01:47 adam + * Removed print of data1 tree on stdout so that inetd works again. + * + * Revision 1.40 2001/03/29 21:31:31 adam + * Fixed "record begin" for Tcl filter. + * + * Revision 1.39 2000/12/05 19:09:15 adam + * Fixed problem where indexer could crash if abstract syntax was undefined. + * + * Revision 1.38 2000/12/05 14:44:58 adam + * Fixed minor bug that could cause zmbol to break it data were emitted + * with not parent tags. + * + * Revision 1.37 2000/12/05 12:22:53 adam + * Termlist source implemented (so that we can index values of XML/SGML + * attributes). + * + * Revision 1.36 2000/12/05 10:01:44 adam * Fixed bug regarding user-defined attribute sets. * * Revision 1.35 2000/11/29 15:21:31 adam @@ -299,6 +318,78 @@ static void grs_destroy(void *clientData) free (h); } +static void index_tag (data1_node *par, data1_node *n, + struct recExtractCtrl *p, int level, RecWord *wrd) +{ + data1_termlist *tlist = 0; + data1_datatype dtype = DATA1K_string; + /* + * cycle up towards the root until we find a tag with an att.. + * this has the effect of indexing locally defined tags with + * the attribute of their ancestor in the record. + */ + + while (!par->u.tag.element) + if (!par->parent || !(par=get_parent_tag(p->dh, par->parent))) + break; + if (!par || !(tlist = par->u.tag.element->termlists)) + return; + if (par->u.tag.element->tag) + dtype = par->u.tag.element->tag->kind; + + for (; tlist; tlist = tlist->next) + { + char xattr[512]; + /* consider source */ + wrd->string = 0; + + if (!strcmp (tlist->source, "data") && n->which == DATA1N_data) + { + wrd->string = n->u.data.data; + wrd->length = n->u.data.len; + } + else if (sscanf (tlist->source, "attr(%511[^)])", xattr) == 1 && + n->which == DATA1N_tag) + { + data1_xattr *p = n->u.tag.attributes; + while (p && strcmp (p->name, xattr)) + p = p->next; + if (p) + { + wrd->string = p->value; + wrd->length = strlen(p->value); + } + } + if (wrd->string) + { + if (p->flagShowRecords) + { + int i; + printf("%*sIdx: [%s]", (level + 1) * 4, "", + tlist->structure); + printf("%s:%s [%d] %s", + tlist->att->parent->name, + tlist->att->name, tlist->att->value, + tlist->source); + printf (" data=\""); + for (i = 0; ilength && i < 8; i++) + fputc (wrd->string[i], stdout); + fputc ('"', stdout); + if (wrd->length > 8) + printf (" ..."); + fputc ('\n', stdout); + } + else + { + wrd->reg_type = *tlist->structure; + wrd->attrSet = (int) (tlist->att->parent->reference); + wrd->attrUse = tlist->att->locals->local; + (*p->tokenAdd)(wrd); + } + } + } +} + static int dumpkeys(data1_node *n, struct recExtractCtrl *p, int level) { RecWord wrd; @@ -346,11 +437,14 @@ static int dumpkeys(data1_node *n, struct recExtractCtrl *p, int level) if (dumpkeys(n->child, p, level + 1) < 0) return -1; + if (n->which == DATA1N_tag) + { + index_tag (n, n, p, level, &wrd); + } + if (n->which == DATA1N_data) { data1_node *par = get_parent_tag(p->dh, n); - data1_termlist *tlist = 0; - data1_datatype dtype = DATA1K_string; if (p->flagShowRecords) { @@ -365,42 +459,9 @@ static int dumpkeys(data1_node *n, struct recExtractCtrl *p, int level) printf("NULL\n"); } - assert(par); - - /* - * cycle up towards the root until we find a tag with an att.. - * this has the effect of indexing locally defined tags with - * the attribute of their ancestor in the record. - */ - - while (!par->u.tag.element) - if (!par->parent || !(par=get_parent_tag(p->dh, par->parent))) - break; - if (!par || !(tlist = par->u.tag.element->termlists)) - continue; - if (par->u.tag.element->tag) - dtype = par->u.tag.element->tag->kind; - for (; tlist; tlist = tlist->next) - { - if (p->flagShowRecords) - { - printf("%*sIdx: [%s]", (level + 1) * 4, "", - tlist->structure); - printf("%s:%s [%d]\n", - tlist->att->parent->name, - tlist->att->name, tlist->att->value); - } - else - { - wrd.reg_type = *tlist->structure; - wrd.string = n->u.data.data; - wrd.length = n->u.data.len; - wrd.attrSet = (int) (tlist->att->parent->reference); - wrd.attrUse = tlist->att->locals->local; - (*p->tokenAdd)(&wrd); - } - } - } + if (par) + index_tag (par, n, p, level, &wrd); + } if (p->flagShowRecords && n->which == DATA1N_root) { printf("%*s-------------\n\n", level * 4, ""); @@ -447,10 +508,15 @@ static int grs_extract_sub(struct grs_handlers *h, struct recExtractCtrl *p, return RECCTRL_EXTRACT_EOF; oe.proto = PROTO_Z3950; oe.oclass = CLASS_SCHEMA; + if (!n->u.root.absyn) + return RECCTRL_EXTRACT_ERROR; oe.value = n->u.root.absyn->reference; if ((oid_ent_to_oid (&oe, oidtmp))) (*p->schemaAdd)(p, oidtmp); +#if 0 + data1_pr_tree (p->dh, n, stdout); +#endif if (dumpkeys(n, p, 0) < 0) { data1_free_tree(p->dh, n); @@ -726,6 +792,9 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) else if (p->comp && !res) selected = 1; +#if 0 + data1_pr_tree (p->dh, node, stdout); +#endif logf (LOG_DEBUG, "grs_retrieve: transfer syntax mapping"); switch (p->output_format = (p->input_format != VAL_NONE ? p->input_format : VAL_SUTRS))