From 03ecbe8fd92f9e55e07a21bc0486e3f78fcaa7cc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 3 Jul 2002 10:05:19 +0000 Subject: [PATCH] Prepare for extra root tag node for better XML support --- index/zinfo.c | 62 ++++++++++++++++++++++++++++-------------------------- index/zrpn.c | 3 ++- recctrl/recgrs.c | 61 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 69 insertions(+), 57 deletions(-) diff --git a/index/zinfo.c b/index/zinfo.c index a29f76a..48e52fb 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zinfo.c,v 1.30 2002-05-13 14:13:43 adam Exp $ + * $Id: zinfo.c,v 1.31 2002-07-03 10:05:19 adam Exp $ */ #include @@ -322,8 +322,8 @@ ZebraExplainInfo zebraExplain_open ( #if ZINFO_DEBUG data1_pr_tree (zei->dh, zei->data1_target, stderr); #endif - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); zebraExplain_mergeAccessInfo (zei, node_tgtinfo, &zei->accessInfo); @@ -426,8 +426,8 @@ ZebraExplainInfo zebraExplain_open ( nmem_destroy (zei->nmem); return 0; } - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); assert (node_tgtinfo); zebraExplain_initCommonInfo (zei, node_tgtinfo); @@ -464,10 +464,8 @@ ZebraExplainInfo zebraExplain_open ( if (zcl->data1_categoryList) { - assert (zcl->data1_categoryList->child); - node_cl = data1_search_tag (zei->dh, - zcl->data1_categoryList->child, - "categoryList"); + node_cl = data1_search_tag (zei->dh, zcl->data1_categoryList, + "/categoryList"); assert (node_cl); zebraExplain_initCommonInfo (zei, node_cl); } @@ -488,8 +486,8 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei, zad->data1_tree = read_sgml_rec (zei->dh, zei->nmem, rec); - node_adinfo = data1_search_tag (zei->dh, zad->data1_tree->child, - "attributeDetails"); + node_adinfo = data1_search_tag (zei->dh, zad->data1_tree, + "/attributeDetails"); node_zebra = data1_search_tag (zei->dh, node_adinfo->child, "zebraInfo"); node_list = data1_search_tag (zei->dh, node_zebra->child, @@ -553,8 +551,9 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, zdi->data1_database = read_sgml_rec (zei->dh, zei->nmem, rec); - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); + assert (node_dbinfo); zebraExplain_mergeAccessInfo (zei, node_dbinfo, &zdi->accessInfo); node_zebra = data1_search_tag (zei->dh, node_dbinfo->child, @@ -715,9 +714,9 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, "\n"); if (!zdi->data1_database) return -2; - - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); assert (node_dbinfo); zebraExplain_initCommonInfo (zei, node_dbinfo); @@ -754,9 +753,8 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, "AttributeDetails\n" "\n"); - node_adinfo = - data1_search_tag (zei->dh, zdi->attributeDetails->data1_tree->child, - "attributeDetails"); + node_adinfo = data1_search_tag (zei->dh, zdi->attributeDetails->data1_tree, + "/attributeDetails"); assert (node_adinfo); zebraExplain_initCommonInfo (zei, node_adinfo); @@ -818,9 +816,9 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, #endif drec = createRecord (zei->records, &sysno); - - node_ci = data1_search_tag (zei->dh, node_categoryList->child, - "categoryList"); + + node_ci = data1_search_tag (zei->dh, node_categoryList, + "/categoryList"); assert (node_ci); node_ci = data1_mk_tag (zei->dh, zei->nmem, "categories", 0 /* attr */, node_ci); @@ -873,8 +871,9 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei, drec = createRecord (zei->records, &zad->sysno); assert (zad->data1_tree); - node_adinfo = data1_search_tag (zei->dh, zad->data1_tree->child, - "attributeDetails"); + + node_adinfo = data1_search_tag (zei->dh, zad->data1_tree, + "/attributeDetails"); zebraExplain_updateCommonInfo (zei, node_adinfo); data1_mk_tag_data_text (zei->dh, node_adinfo, "name", @@ -999,9 +998,11 @@ static void zebraExplain_writeDatabase (ZebraExplainInfo zei, #endif drec = createRecord (zei->records, &zdi->sysno); assert (zdi->data1_database); - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); + + assert (node_dbinfo); zebraExplain_updateCommonInfo (zei, node_dbinfo); zebraExplain_updateAccessInfo (zei, node_dbinfo, zdi->accessInfo); @@ -1087,9 +1088,10 @@ static void zebraExplain_writeAttributeSet (ZebraExplainInfo zei, "AttributeSetInfo\n" "\n" ); - node_attinfo = data1_search_tag (zei->dh, node_root->child, - "attributeSetInfo"); + node_attinfo = data1_search_tag (zei->dh, node_root, + "/attributeSetInfo"); + assert (node_attinfo); zebraExplain_initCommonInfo (zei, node_attinfo); zebraExplain_updateCommonInfo (zei, node_attinfo); @@ -1145,8 +1147,8 @@ static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush) trec = rec_get (zei->records, 1); xfree (trec->info[recInfo_storeData]); - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); assert (node_tgtinfo); zebraExplain_updateCommonInfo (zei, node_tgtinfo); diff --git a/index/zrpn.c b/index/zrpn.c index 78f6180..846c1ed 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -3,7 +3,7 @@ * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: zrpn.c,v 1.115 2002-04-13 18:16:43 adam Exp $ + * $Id: zrpn.c,v 1.116 2002-07-03 10:05:19 adam Exp $ */ #include #include @@ -891,6 +891,7 @@ static int string_term (ZebraHandle zh, Z_AttributesPlusTerm *zapt, curAttributeSet, use_value, r); if (r == -1) { + /* set was found, but value wasn't defined */ char val_str[32]; sprintf (val_str, "%d", use_value); zh->errCode = 114; diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index bc0c974..1e0c72a 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -2,7 +2,7 @@ * Copyright (C) 1994-2002, Index Data * All rights reserved. * - * $Id: recgrs.c,v 1.52 2002-07-02 20:20:09 adam Exp $ + * $Id: recgrs.c,v 1.53 2002-07-03 10:05:19 adam Exp $ */ #include @@ -146,20 +146,12 @@ static void index_xpath (data1_node *n, struct recExtractCtrl *p, tag_path_full[flen++] = '/'; } else if (nn->which == DATA1N_root) - { - size_t tlen = strlen(nn->u.root.type); - if (tlen + flen > (sizeof(tag_path_full)-2)) - return; - memcpy (tag_path_full + flen, nn->u.root.type, tlen); - flen += tlen; - tag_path_full[flen++] = '/'; break; - } } wrd->reg_type = '0'; wrd->string = tag_path_full; wrd->length = flen; - wrd->attrSet = VAL_IDXPATH, + wrd->attrSet = VAL_IDXPATH; wrd->attrUse = use; if (p->flagShowRecords) { @@ -502,9 +494,33 @@ static int process_comp(data1_handle dh, data1_node *n, Z_RecordComposition *c) } } +static void add_idzebra_info (struct recRetrieveCtrl *p, data1_node *top, + NMEM mem) +{ + const char *idzebra_ns[7]; + + idzebra_ns[0] = "xmlns:idzebra"; + idzebra_ns[1] = "http://www.indexdata.dk/zebra/"; + idzebra_ns[2] = 0; + + data1_tag_add_attr (p->dh, mem, top, idzebra_ns); + + data1_mk_tag_data_int (p->dh, top, "idzebra:size", p->recordSize, + mem); + if (p->score != -1) + data1_mk_tag_data_int (p->dh, top, "idzebra:score", + p->score, mem); + + data1_mk_tag_data_int (p->dh, top, "idzebra:localnumber", p->localno, + mem); + if (p->fname) + data1_mk_tag_data_text(p->dh, top, "idzebra:filename", + p->fname, mem); +} + static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) { - data1_node *node = 0, *onode = 0; + data1_node *node = 0, *onode = 0, *top; data1_node *dnew; data1_maptab *map; int res, selected = 0; @@ -542,8 +558,10 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) #if 0 data1_pr_tree (p->dh, node, stdout); #endif + top = data1_get_root_tag (p->dh, node); + logf (LOG_DEBUG, "grs_retrieve: size"); - if ((dnew = data1_mk_tag_data_wd(p->dh, node, "size", mem))) + if ((dnew = data1_mk_tag_data_wd(p->dh, top, "size", mem))) { dnew->u.data.what = DATA1I_text; dnew->u.data.data = dnew->lbuf; @@ -553,7 +571,7 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) tagname = res_get_def(p->res, "tagrank", "rank"); if (strcmp(tagname, "0") && p->score >= 0 && - (dnew = data1_mk_tag_data_wd(p->dh, node, tagname, mem))) + (dnew = data1_mk_tag_data_wd(p->dh, top, tagname, mem))) { logf (LOG_DEBUG, "grs_retrieve: %s", tagname); dnew->u.data.what = DATA1I_num; @@ -564,11 +582,12 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) tagname = res_get_def(p->res, "tagsysno", "localControlNumber"); if (strcmp(tagname, "0") && p->localno > 0 && - (dnew = data1_mk_tag_data_wd(p->dh, node, tagname, mem))) + (dnew = data1_mk_tag_data_wd(p->dh, top, tagname, mem))) { logf (LOG_DEBUG, "grs_retrieve: %s", tagname); dnew->u.data.what = DATA1I_text; dnew->u.data.data = dnew->lbuf; + sprintf(dnew->u.data.data, "%d", p->localno); dnew->u.data.len = strlen(dnew->u.data.data); } @@ -695,18 +714,8 @@ static int grs_retrieve(void *clientData, struct recRetrieveCtrl *p) { case VAL_TEXT_XML: - data1_mk_tag_data_int (p->dh, node, "idzebra:size", p->recordSize, - mem); - if (p->score != -1) - data1_mk_tag_data_int (p->dh, node, "idzebra:score", - p->score, mem); - - data1_mk_tag_data_int (p->dh, node, "idzebra:localnumber", p->localno, - mem); - if (p->fname) - data1_mk_tag_data_text(p->dh, node, "idzebra:filename", - p->fname, mem); - + add_idzebra_info (p, top, mem); + if (!(p->rec_buf = data1_nodetoidsgml(p->dh, node, selected, &p->rec_len))) p->diagnostic = 238; -- 1.7.10.4