1 /* $Id: zinfo.c,v 1.61 2006-05-10 13:46:55 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <sys/types.h>
29 #include <idzebra/version.h>
36 #define ZEB_SU_SET_USE 1
48 zint term_occurrences;
52 struct zebSUInfo info;
53 struct zebSUInfoB *next;
56 typedef struct zebAccessObjectB *zebAccessObject;
57 struct zebAccessObjectB {
64 typedef struct zebAccessInfoB *zebAccessInfo;
65 struct zebAccessInfoB {
66 zebAccessObject attributeSetIds;
67 zebAccessObject schemas;
71 struct zebSUInfoB *SUInfo;
75 data1_node *data1_tree;
76 } *zebAttributeDetails;
78 struct zebDatabaseInfoB {
79 zebAttributeDetails attributeDetails;
82 data1_node *data1_database;
83 zint recordCount; /* records in db */
84 zint recordBytes; /* size of records */
85 SYSNO sysno; /* sysno of database info */
86 int readFlag; /* 1: read is needed when referenced; 0 if not */
87 int dirty; /* 1: database is dirty: write is needed */
88 struct zebDatabaseInfoB *next;
89 zebAccessInfo accessInfo;
92 struct zebraExplainAttset {
95 struct zebraExplainAttset *next;
98 struct zebraCategoryListInfo {
101 data1_node *data1_categoryList;
104 struct zebraExplainInfo {
113 struct zebraExplainAttset *attsets;
115 data1_node *data1_target;
116 struct zebraCategoryListInfo *categoryList;
117 struct zebDatabaseInfoB *databaseInfo;
118 struct zebDatabaseInfoB *curDatabaseInfo;
119 zebAccessInfo accessInfo;
120 char date[15]; /* YYYY MMDD HH MM SS */
121 int (*updateFunc)(void *handle, Record drec, data1_node *n);
125 static void zebraExplain_initCommonInfo(ZebraExplainInfo zei, data1_node *n);
126 static void zebraExplain_initAccessInfo(ZebraExplainInfo zei, data1_node *n);
128 static data1_node *read_sgml_rec(data1_handle dh, NMEM nmem, Record rec)
130 return data1_read_sgml(dh, nmem, rec->info[recInfo_storeData]);
133 static void zebraExplain_writeDatabase(ZebraExplainInfo zei,
134 struct zebDatabaseInfoB *zdi,
136 static void zebraExplain_writeAttributeDetails(ZebraExplainInfo zei,
137 zebAttributeDetails zad,
138 const char *databaseName,
140 static void zebraExplain_writeTarget(ZebraExplainInfo zei, int key_flush);
141 static void zebraExplain_writeAttributeSet(ZebraExplainInfo zei,
144 static void zebraExplain_writeCategoryList(ZebraExplainInfo zei,
145 struct zebraCategoryListInfo *zcl,
149 static Record createRecord(Records records, SYSNO *sysno)
154 rec = rec_get(records, *sysno);
157 xfree(rec->info[recInfo_storeData]);
161 rec = rec_new(records);
166 rec->info[recInfo_fileType] =
167 rec_strdup("grs.sgml", &rec->size[recInfo_fileType]);
168 rec->info[recInfo_databaseName] =
169 rec_strdup("IR-Explain-1",
170 &rec->size[recInfo_databaseName]);
175 void zebraExplain_flush(ZebraExplainInfo zei, void *handle)
179 zei->updateHandle = handle;
182 struct zebDatabaseInfoB *zdi;
185 /* write each database info record */
186 for (zdi = zei->databaseInfo; zdi; zdi = zdi->next)
188 zebraExplain_writeDatabase(zei, zdi, 1);
189 zebraExplain_writeAttributeDetails(zei, zdi->attributeDetails,
190 zdi->databaseName, 1);
192 zebraExplain_writeTarget(zei, 1);
193 zebraExplain_writeCategoryList(zei,
196 assert(zei->accessInfo);
197 for (o = zei->accessInfo->attributeSetIds; o; o = o->next)
199 zebraExplain_writeAttributeSet(zei, o, 1);
200 for (o = zei->accessInfo->schemas; o; o = o->next)
203 /* zebraExplain_writeSchema(zei, o, 1); */
206 for (zdi = zei->databaseInfo; zdi; zdi = zdi->next)
208 zebraExplain_writeDatabase(zei, zdi, 0);
209 zebraExplain_writeAttributeDetails(zei, zdi->attributeDetails,
210 zdi->databaseName, 0);
212 zebraExplain_writeTarget(zei, 0);
216 void zebraExplain_close(ZebraExplainInfo zei)
219 yaz_log(YLOG_LOG, "zebraExplain_close");
223 zebraExplain_flush(zei, zei->updateHandle);
224 nmem_destroy(zei->nmem);
227 void zebraExplain_mergeOids (ZebraExplainInfo zei, data1_node *n,
232 for (np = n->child; np; np = np->next)
239 if (np->which != DATA1N_tag || strcmp(np->u.tag.tag, "oid"))
241 len = np->child->u.data.len;
244 memcpy(str, np->child->u.data.data, len);
247 oid = odr_getoidbystr_nmem(zei->nmem, str);
249 for (ao = *op; ao; ao = ao->next)
250 if (!oid_oidcmp(oid, ao->oid))
257 ao = (zebAccessObject) nmem_malloc(zei->nmem, sizeof(*ao));
267 void zebraExplain_mergeAccessInfo(ZebraExplainInfo zei, data1_node *n,
268 zebAccessInfo *accessInfo)
274 *accessInfo = (zebAccessInfo)
275 nmem_malloc(zei->nmem, sizeof(**accessInfo));
276 (*accessInfo)->attributeSetIds = NULL;
277 (*accessInfo)->schemas = NULL;
281 if (!(n = data1_search_tag(zei->dh, n->child, "accessInfo")))
283 if ((np = data1_search_tag(zei->dh, n->child, "attributeSetIds")))
284 zebraExplain_mergeOids(zei, np,
285 &(*accessInfo)->attributeSetIds);
286 if ((np = data1_search_tag(zei->dh, n->child, "schemas")))
287 zebraExplain_mergeOids(zei, np,
288 &(*accessInfo)->schemas);
297 databaseList (list of databases)
302 targetInfo: TargetInfo
309 dateAdded: 20030630190601
310 dateChanged: 20030630190601
316 oid: 1.2.840.10003.3.2
317 oid: 1.2.840.10003.3.5
318 oid: 1.2.840.10003.3.1
320 oid: 1.2.840.10003.13.1000.81.2
321 oid: 1.2.840.10003.13.2
328 attributeDetailsId: 51
332 attributeDetailsId: 53
335 nextResultSetPosition = 2
338 ZebraExplainInfo zebraExplain_open(
339 Records records, data1_handle dh,
343 int (*updateFunc)(void *handle, Record drec, data1_node *n))
346 ZebraExplainInfo zei;
347 struct zebDatabaseInfoB **zdip;
350 NMEM nmem = nmem_create();
353 yaz_log(YLOG_LOG, "zebraExplain_open wr=%d", writeFlag);
355 zei = (ZebraExplainInfo) nmem_malloc(nmem, sizeof(*zei));
356 zei->databaseInfo = 0;
357 zei->write_flag = writeFlag;
358 zei->updateHandle = updateHandle;
359 zei->updateFunc = updateFunc;
361 zei->ordinalDatabase = 1;
362 zei->curDatabaseInfo = NULL;
363 zei->records = records;
368 zei->categoryList = (struct zebraCategoryListInfo *)
369 nmem_malloc(zei->nmem, sizeof(*zei->categoryList));
370 zei->categoryList->sysno = 0;
371 zei->categoryList->dirty = 0;
372 zei->categoryList->data1_categoryList = NULL;
374 if ( atoi(res_get_def(res, "notimestamps", "0") )== 0)
377 tm = localtime(&our_time);
378 sprintf(zei->date, "%04d%02d%02d%02d%02d%02d",
379 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
380 tm->tm_hour, tm->tm_min, tm->tm_sec);
382 sprintf(zei->date, "%04d%02d%02d%02d%02d%02d",
385 zdip = &zei->databaseInfo;
386 trec = rec_get_root(records); /* get "root" record */
391 zebraExplain_mergeAccessInfo(zei, 0, &zei->accessInfo);
392 if (trec) /* targetInfo already exists ... */
394 data1_node *node_tgtinfo, *node_zebra, *node_list, *np;
396 zei->data1_target = read_sgml_rec(zei->dh, zei->nmem, trec);
398 if (!zei->data1_target || !zei->data1_target->u.root.absyn)
400 if (!zei->data1_target)
403 yaz_log(YLOG_FATAL, "Explain schema missing. Check profilePath");
404 nmem_destroy(zei->nmem);
408 data1_pr_tree(zei->dh, zei->data1_target, stderr);
410 node_tgtinfo = data1_search_tag(zei->dh, zei->data1_target,
412 zebraExplain_mergeAccessInfo(zei, node_tgtinfo,
415 node_zebra = data1_search_tag(zei->dh, node_tgtinfo->child,
420 node_list = data1_search_tag(zei->dh, node_zebra->child,
423 np = node_list->child;
425 for(; np; np = np->next)
427 data1_node *node_name = NULL;
428 data1_node *node_id = NULL;
429 data1_node *node_aid = NULL;
431 if (np->which != DATA1N_tag || strcmp(np->u.tag.tag, "database"))
433 for(np2 = np->child; np2; np2 = np2->next)
435 if (np2->which != DATA1N_tag)
437 if (!strcmp(np2->u.tag.tag, "name"))
438 node_name = np2->child;
439 else if (!strcmp(np2->u.tag.tag, "id"))
440 node_id = np2->child;
441 else if (!strcmp(np2->u.tag.tag, "attributeDetailsId"))
442 node_aid = np2->child;
444 assert(node_id && node_name && node_aid);
446 *zdip =(struct zebDatabaseInfoB *)
447 nmem_malloc(zei->nmem, sizeof(**zdip));
448 (*zdip)->readFlag = 1;
450 (*zdip)->data1_database = NULL;
451 (*zdip)->recordCount = 0;
452 (*zdip)->recordBytes = 0;
453 zebraExplain_mergeAccessInfo (zei, 0, &(*zdip)->accessInfo);
455 (*zdip)->databaseName = (char *)
456 nmem_malloc (zei->nmem, 1+node_name->u.data.len);
457 memcpy((*zdip)->databaseName, node_name->u.data.data,
458 node_name->u.data.len);
459 (*zdip)->databaseName[node_name->u.data.len] = '\0';
460 (*zdip)->sysno = atoi_zn (node_id->u.data.data,
461 node_id->u.data.len);
462 (*zdip)->attributeDetails = (zebAttributeDetails)
463 nmem_malloc (zei->nmem, sizeof(*(*zdip)->attributeDetails));
464 (*zdip)->attributeDetails->sysno = atoi_zn (node_aid->u.data.data,
465 node_aid->u.data.len);
466 (*zdip)->attributeDetails->readFlag = 1;
467 (*zdip)->attributeDetails->dirty = 0;
468 (*zdip)->attributeDetails->SUInfo = NULL;
470 zdip = &(*zdip)->next;
474 np = data1_search_tag(zei->dh, node_zebra->child,
477 assert (np && np->which == DATA1N_data);
478 zei->ordinalSU = atoi_n(np->u.data.data, np->u.data.len);
480 np = data1_search_tag(zei->dh, node_zebra->child,
483 assert (np && np->which == DATA1N_data);
484 zei->ordinalDatabase = atoi_n(np->u.data.data, np->u.data.len);
486 np = data1_search_tag(zei->dh, node_zebra->child,
489 assert (np && np->which == DATA1N_data);
490 zei->runNumber = atoi_zn(np->u.data.data, np->u.data.len);
491 yaz_log(YLOG_DEBUG, "read runnumber=" ZINT_FORMAT, zei->runNumber);
496 else /* create initial targetInfo */
498 data1_node *node_tgtinfo;
507 data1_read_sgml(zei->dh, zei->nmem,
508 "<explain><targetInfo>TargetInfo\n"
510 "<namedResultSets>1</>\n"
511 "<multipleDBSearch>1</>\n"
512 "<nicknames><name>Zebra</></>\n"
514 if (!zei->data1_target)
516 yaz_log(YLOG_FATAL, "Explain schema missing. Check profilePath");
517 nmem_destroy(zei->nmem);
520 node_tgtinfo = data1_search_tag(zei->dh, zei->data1_target,
522 assert(node_tgtinfo);
524 zebraExplain_initCommonInfo(zei, node_tgtinfo);
525 zebraExplain_initAccessInfo(zei, node_tgtinfo);
527 /* write now because we want to be sure about the sysno */
528 trec = rec_new(records);
531 yaz_log(YLOG_FATAL, "Cannot create root Explain record");
532 nmem_destroy(zei->nmem);
535 trec->info[recInfo_fileType] =
536 rec_strdup("grs.sgml", &trec->size[recInfo_fileType]);
537 trec->info[recInfo_databaseName] =
538 rec_strdup("IR-Explain-1", &trec->size[recInfo_databaseName]);
540 sgml_buf = data1_nodetoidsgml(dh, zei->data1_target, 0, &sgml_len);
541 trec->info[recInfo_storeData] = (char *) xmalloc(sgml_len);
542 memcpy(trec->info[recInfo_storeData], sgml_buf, sgml_len);
543 trec->size[recInfo_storeData] = sgml_len;
545 rec_put(records, &trec);
549 zebraExplain_newDatabase(zei, "IR-Explain-1", 0);
551 if (!zei->categoryList->dirty)
553 struct zebraCategoryListInfo *zcl = zei->categoryList;
557 zcl->data1_categoryList =
558 data1_read_sgml(zei->dh, zei->nmem,
559 "<explain><categoryList>CategoryList\n"
562 if (zcl->data1_categoryList)
564 node_cl = data1_search_tag(zei->dh, zcl->data1_categoryList,
567 zebraExplain_initCommonInfo(zei, node_cl);
574 static void zebraExplain_readAttributeDetails(ZebraExplainInfo zei,
575 zebAttributeDetails zad)
578 struct zebSUInfoB **zsuip = &zad->SUInfo;
579 data1_node *node_adinfo, *node_zebra, *node_list, *np;
582 rec = rec_get(zei->records, zad->sysno);
584 zad->data1_tree = read_sgml_rec(zei->dh, zei->nmem, rec);
586 node_adinfo = data1_search_tag(zei->dh, zad->data1_tree,
587 "/attributeDetails");
588 node_zebra = data1_search_tag(zei->dh, node_adinfo->child,
590 node_list = data1_search_tag(zei->dh, node_zebra->child,
592 for (np = node_list->child; np; np = np->next)
594 data1_node *node_set = NULL;
595 data1_node *node_use = NULL;
596 data1_node *node_str = NULL;
597 data1_node *node_ordinal = NULL;
598 data1_node *node_type = NULL;
599 data1_node *node_doc_occurrences = NULL;
600 data1_node *node_term_occurrences = NULL;
605 if (np->which != DATA1N_tag || strcmp(np->u.tag.tag, "attr"))
607 for (np2 = np->child; np2; np2 = np2->next)
609 if (np2->which != DATA1N_tag || !np2->child ||
610 np2->child->which != DATA1N_data)
612 if (!strcmp(np2->u.tag.tag, "set"))
613 node_set = np2->child;
614 else if (!strcmp(np2->u.tag.tag, "use"))
615 node_use = np2->child;
616 else if (!strcmp(np2->u.tag.tag, "str"))
617 node_str = np2->child;
618 else if (!strcmp(np2->u.tag.tag, "ordinal"))
619 node_ordinal = np2->child;
620 else if (!strcmp(np2->u.tag.tag, "type"))
621 node_type = np2->child;
622 else if (!strcmp(np2->u.tag.tag, "dococcurrences"))
623 node_doc_occurrences = np2->child;
624 else if (!strcmp(np2->u.tag.tag, "termoccurrences"))
625 node_term_occurrences = np2->child;
628 yaz_log(YLOG_LOG, "Unknown tag '%s' in attributeDetails",
632 assert(node_ordinal);
634 *zsuip = (struct zebSUInfoB *)
635 nmem_malloc(zei->nmem, sizeof(**zsuip));
637 if (node_type && node_type->u.data.len > 0)
638 (*zsuip)->info.index_type = node_type->u.data.data[0];
641 yaz_log(YLOG_WARN, "Missing attribute 'type' in attribute info");
642 (*zsuip)->info.index_type = 'w';
645 if (node_doc_occurrences)
647 data1_node *np = node_doc_occurrences;
648 (*zsuip)->info.doc_occurrences = atoi_zn(np->u.data.data,
651 if (node_term_occurrences)
653 data1_node *np = node_term_occurrences;
654 (*zsuip)->info.term_occurrences = atoi_zn(np->u.data.data,
657 if (node_set && node_use)
659 (*zsuip)->info.which = ZEB_SU_SET_USE;
661 oid_str_len = node_set->u.data.len;
662 if (oid_str_len >= (int) sizeof(oid_str))
663 oid_str_len = sizeof(oid_str)-1;
664 memcpy(oid_str, node_set->u.data.data, oid_str_len);
665 oid_str[oid_str_len] = '\0';
667 (*zsuip)->info.u.su.set = oid_getvalbyname(oid_str);
669 (*zsuip)->info.u.su.use = atoi_n(node_use->u.data.data,
670 node_use->u.data.len);
671 yaz_log(YLOG_DEBUG, "set=%d use=%d ordinal=%d",
672 (*zsuip)->info.u.su.set, (*zsuip)->info.u.su.use,
673 (*zsuip)->info.ordinal);
677 (*zsuip)->info.which = ZEB_SU_STR;
679 (*zsuip)->info.u.str = nmem_strdupn(zei->nmem,
680 node_str->u.data.data,
681 node_str->u.data.len);
685 yaz_log(YLOG_WARN, "Missing set/use/str in attribute info");
688 (*zsuip)->info.ordinal = atoi_n (node_ordinal->u.data.data,
689 node_ordinal->u.data.len);
690 zsuip = &(*zsuip)->next;
697 static void zebraExplain_readDatabase (ZebraExplainInfo zei,
698 struct zebDatabaseInfoB *zdi)
701 data1_node *node_dbinfo, *node_zebra, *np;
704 rec = rec_get (zei->records, zdi->sysno);
706 zdi->data1_database = read_sgml_rec (zei->dh, zei->nmem, rec);
708 node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database,
710 assert (node_dbinfo);
711 zebraExplain_mergeAccessInfo (zei, node_dbinfo, &zdi->accessInfo);
713 node_zebra = data1_search_tag (zei->dh, node_dbinfo->child,
716 && (np = data1_search_tag (zei->dh, node_zebra->child,
718 && np->child && np->child->which == DATA1N_data)
719 zdi->recordBytes = atoi_zn (np->child->u.data.data,
720 np->child->u.data.len);
723 && (np = data1_search_tag (zei->dh, node_zebra->child,
725 && np->child && np->child->which == DATA1N_data)
726 zdi->ordinalDatabase = atoi_n(np->child->u.data.data,
727 np->child->u.data.len);
729 if ((np = data1_search_tag (zei->dh, node_dbinfo->child,
731 (np = data1_search_tag (zei->dh, np->child,
732 "recordCountActual")) &&
733 np->child->which == DATA1N_data)
735 zdi->recordCount = atoi_zn (np->child->u.data.data,
736 np->child->u.data.len);
742 int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle)
744 struct zebDatabaseInfoB **zdip = &zei->databaseInfo;
748 if (*zdip == zei->curDatabaseInfo)
750 struct zebDatabaseInfoB *zdi = *zdip;
754 zei->updateHandle = update_handle;
756 if (zdi->attributeDetails)
758 /* remove attribute details keys and delete it */
759 zebAttributeDetails zad = zdi->attributeDetails;
761 rec = rec_get(zei->records, zad->sysno);
762 (*zei->updateFunc)(zei->updateHandle, rec, 0);
765 /* remove database record keys and delete it */
766 rec = rec_get (zei->records, zdi->sysno);
767 (*zei->updateFunc)(zei->updateHandle, rec, 0);
770 /* remove from list */
773 /* current database is IR-Explain-1 */
776 zdip = &(*zdip)->next;
781 int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database)
783 struct zebDatabaseInfoB *zdi;
784 const char *database_n = strrchr (database, '/');
789 database_n = database;
792 if (zei->curDatabaseInfo &&
793 !STRCASECMP (zei->curDatabaseInfo->databaseName, database))
795 for (zdi = zei->databaseInfo; zdi; zdi=zdi->next)
797 if (!STRCASECMP (zdi->databaseName, database_n))
803 yaz_log(YLOG_LOG, "zebraExplain_curDatabase: %s", database);
808 yaz_log(YLOG_LOG, "zebraExplain_readDatabase: %s", database);
810 zebraExplain_readDatabase (zei, zdi);
812 if (zdi->attributeDetails->readFlag)
815 yaz_log(YLOG_LOG, "zebraExplain_readAttributeDetails: %s", database);
817 zebraExplain_readAttributeDetails (zei, zdi->attributeDetails);
819 zei->curDatabaseInfo = zdi;
823 static void zebraExplain_initCommonInfo (ZebraExplainInfo zei, data1_node *n)
825 data1_node *c = data1_mk_tag (zei->dh, zei->nmem, "commonInfo", 0, n);
826 data1_mk_tag_data_text (zei->dh, c, "dateAdded", zei->date, zei->nmem);
827 data1_mk_tag_data_text (zei->dh, c, "dateChanged", zei->date, zei->nmem);
828 data1_mk_tag_data_text (zei->dh, c, "languageCode", "EN", zei->nmem);
831 static void zebraExplain_updateCommonInfo (ZebraExplainInfo zei, data1_node *n)
833 data1_node *c = data1_search_tag (zei->dh, n->child, "commonInfo");
835 data1_mk_tag_data_text_uni (zei->dh, c, "dateChanged", zei->date,
839 static void zebraExplain_initAccessInfo (ZebraExplainInfo zei, data1_node *n)
841 data1_node *c = data1_mk_tag (zei->dh, zei->nmem, "accessInfo", 0, n);
842 data1_node *d = data1_mk_tag (zei->dh, zei->nmem, "unitSystems", 0, c);
843 data1_mk_tag_data_text (zei->dh, d, "string", "ISO", zei->nmem);
846 static void zebraExplain_updateAccessInfo (ZebraExplainInfo zei, data1_node *n,
847 zebAccessInfo accessInfo)
849 data1_node *c = data1_search_tag (zei->dh, n->child, "accessInfo");
855 data1_pr_tree (zei->dh, n, stdout);
860 if ((p = accessInfo->attributeSetIds))
862 d = data1_mk_tag_uni (zei->dh, zei->nmem, "attributeSetIds", c);
863 for (; p; p = p->next)
864 data1_mk_tag_data_oid (zei->dh, d, "oid", p->oid, zei->nmem);
866 if ((p = accessInfo->schemas))
868 d = data1_mk_tag_uni (zei->dh, zei->nmem, "schemas", c);
869 for (; p; p = p->next)
870 data1_mk_tag_data_oid (zei->dh, d, "oid", p->oid, zei->nmem);
874 int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database,
875 int explain_database)
877 struct zebDatabaseInfoB *zdi;
878 data1_node *node_dbinfo, *node_adinfo;
879 const char *database_n = strrchr (database, '/');
884 database_n = database;
887 yaz_log(YLOG_LOG, "zebraExplain_newDatabase: %s", database);
890 for (zdi = zei->databaseInfo; zdi; zdi=zdi->next)
892 if (!STRCASECMP (zdi->databaseName, database_n))
897 /* it's new really. make it */
898 zdi = (struct zebDatabaseInfoB *) nmem_malloc (zei->nmem, sizeof(*zdi));
899 zdi->next = zei->databaseInfo;
900 zei->databaseInfo = zdi;
902 zdi->recordCount = 0;
903 zdi->recordBytes = 0;
905 zdi->databaseName = nmem_strdup (zei->nmem, database_n);
907 zdi->ordinalDatabase = zei->ordinalDatabase++;
909 zebraExplain_mergeAccessInfo (zei, 0, &zdi->accessInfo);
914 zdi->data1_database =
915 data1_read_sgml (zei->dh, zei->nmem,
916 "<explain><databaseInfo>DatabaseInfo\n"
918 if (!zdi->data1_database)
921 node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database,
923 assert (node_dbinfo);
925 zebraExplain_initCommonInfo (zei, node_dbinfo);
926 zebraExplain_initAccessInfo (zei, node_dbinfo);
928 data1_mk_tag_data_text (zei->dh, node_dbinfo, "name",
929 database, zei->nmem);
931 if (explain_database)
932 data1_mk_tag_data_text (zei->dh, node_dbinfo, "explainDatabase",
935 data1_mk_tag_data_text (zei->dh, node_dbinfo, "userFee",
938 data1_mk_tag_data_text (zei->dh, node_dbinfo, "available",
942 data1_pr_tree (zei->dh, zdi->data1_database, stderr);
946 zei->curDatabaseInfo = zdi;
948 zdi->attributeDetails = (zebAttributeDetails)
949 nmem_malloc (zei->nmem, sizeof(*zdi->attributeDetails));
950 zdi->attributeDetails->readFlag = 0;
951 zdi->attributeDetails->sysno = 0;
952 zdi->attributeDetails->dirty = 1;
953 zdi->attributeDetails->SUInfo = NULL;
954 zdi->attributeDetails->data1_tree =
955 data1_read_sgml (zei->dh, zei->nmem,
956 "<explain><attributeDetails>AttributeDetails\n"
959 node_adinfo = data1_search_tag (zei->dh, zdi->attributeDetails->data1_tree,
960 "/attributeDetails");
961 assert (node_adinfo);
963 zebraExplain_initCommonInfo (zei, node_adinfo);
968 static void writeAttributeValueDetails (ZebraExplainInfo zei,
969 zebAttributeDetails zad,
970 data1_node *node_atvs, data1_attset *attset)
973 struct zebSUInfoB *zsui;
974 int set_ordinal = attset->reference;
975 data1_attset_child *c;
977 for (c = attset->children; c; c = c->next)
978 writeAttributeValueDetails (zei, zad, node_atvs, c->child);
979 for (zsui = zad->SUInfo; zsui; zsui = zsui->next)
981 if (zsui->info.which == ZEB_SU_SET_USE &&
982 set_ordinal == zsui->info.u.su.set)
984 data1_node *node_attvalue, *node_value;
985 node_attvalue = data1_mk_tag (zei->dh, zei->nmem, "attributeValue",
986 0 /* attr */, node_atvs);
987 node_value = data1_mk_tag (zei->dh, zei->nmem, "value",
988 0 /* attr */, node_attvalue);
989 data1_mk_tag_data_int (zei->dh, node_value, "numeric",
990 zsui->info.u.su.use, zei->nmem);
995 static void zebraExplain_writeCategoryList (ZebraExplainInfo zei,
996 struct zebraCategoryListInfo *zcl,
1003 data1_node *node_ci, *node_categoryList;
1005 static char *category[] = {
1017 node_categoryList = zcl->data1_categoryList;
1020 yaz_log(YLOG_LOG, "zebraExplain_writeCategoryList");
1023 drec = createRecord (zei->records, &sysno);
1027 node_ci = data1_search_tag (zei->dh, node_categoryList,
1030 node_ci = data1_mk_tag (zei->dh, zei->nmem, "categories", 0 /* attr */,
1034 for (i = 0; category[i]; i++)
1036 data1_node *node_cat = data1_mk_tag (zei->dh, zei->nmem, "category",
1037 0 /* attr */, node_ci);
1039 data1_mk_tag_data_text (zei->dh, node_cat, "name",
1040 category[i], zei->nmem);
1042 /* extract *searchable* keys from it. We do this here, because
1043 record count, etc. is affected */
1045 (*zei->updateFunc)(zei->updateHandle, drec, node_categoryList);
1047 /* convert to "SGML" and write it */
1049 data1_pr_tree (zei->dh, node_categoryList, stderr);
1051 sgml_buf = data1_nodetoidsgml(zei->dh, node_categoryList, 0, &sgml_len);
1052 drec->info[recInfo_storeData] = (char *) xmalloc (sgml_len);
1053 memcpy (drec->info[recInfo_storeData], sgml_buf, sgml_len);
1054 drec->size[recInfo_storeData] = sgml_len;
1056 rec_put (zei->records, &drec);
1059 static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei,
1060 zebAttributeDetails zad,
1061 const char *databaseName,
1067 data1_node *node_adinfo, *node_list, *node_zebra, *node_attributesBySet;
1068 struct zebSUInfoB *zsui;
1076 yaz_log(YLOG_LOG, "zebraExplain_writeAttributeDetails");
1079 drec = createRecord (zei->records, &zad->sysno);
1082 assert (zad->data1_tree);
1084 node_adinfo = data1_search_tag (zei->dh, zad->data1_tree,
1085 "/attributeDetails");
1086 zebraExplain_updateCommonInfo (zei, node_adinfo);
1088 data1_mk_tag_data_text (zei->dh, node_adinfo, "name",
1089 databaseName, zei->nmem);
1091 /* extract *searchable* keys from it. We do this here, because
1092 record count, etc. is affected */
1094 (*zei->updateFunc)(zei->updateHandle, drec, zad->data1_tree);
1096 node_attributesBySet = data1_mk_tag_uni (zei->dh, zei->nmem,
1097 "attributesBySet", node_adinfo);
1101 data1_node *node_asd;
1102 data1_attset *attset;
1103 int set_ordinal = -1;
1104 for (zsui = zad->SUInfo; zsui; zsui = zsui->next)
1106 if (zsui->info.which == ZEB_SU_SET_USE &&
1107 (set_ordinal < 0 || set_ordinal > zsui->info.u.su.set)
1108 && zsui->info.u.su.set > set_min)
1109 set_ordinal = zsui->info.u.su.set;
1111 if (set_ordinal < 0)
1113 set_min = set_ordinal;
1114 node_asd = data1_mk_tag (zei->dh, zei->nmem,
1115 "attributeSetDetails",
1116 0 /* attr */, node_attributesBySet);
1118 attset = data1_attset_search_id (zei->dh, set_ordinal);
1121 zebraExplain_loadAttsets (zei->dh, zei->res);
1122 attset = data1_attset_search_id (zei->dh, set_ordinal);
1129 oe.proto = PROTO_Z3950;
1130 oe.oclass = CLASS_ATTSET;
1131 oe.value = (enum oid_value) set_ordinal;
1133 if (oid_ent_to_oid (&oe, oid))
1135 data1_node *node_abt, *node_atd, *node_atvs;
1136 data1_mk_tag_data_oid (zei->dh, node_asd, "oid",
1139 node_abt = data1_mk_tag (zei->dh, zei->nmem,
1141 0 /*attr */, node_asd);
1142 node_atd = data1_mk_tag (zei->dh, zei->nmem,
1143 "attributeTypeDetails",
1144 0 /* attr */, node_abt);
1145 data1_mk_tag_data_int (zei->dh, node_atd,
1146 "type", 1, zei->nmem);
1147 node_atvs = data1_mk_tag (zei->dh, zei->nmem,
1149 0 /* attr */, node_atd);
1150 writeAttributeValueDetails (zei, zad, node_atvs, attset);
1154 /* zebra info (private) */
1155 node_zebra = data1_mk_tag_uni (zei->dh, zei->nmem,
1156 "zebraInfo", node_adinfo);
1157 node_list = data1_mk_tag_uni (zei->dh, zei->nmem,
1158 "attrlist", node_zebra);
1159 for (zsui = zad->SUInfo; zsui; zsui = zsui->next)
1161 struct oident oident;
1163 data1_node *node_attr;
1164 char index_type_str[2];
1167 node_attr = data1_mk_tag (zei->dh, zei->nmem, "attr", 0 /* attr */,
1170 index_type_str[0] = zsui->info.index_type;
1171 index_type_str[1] = '\0';
1172 data1_mk_tag_data_text (zei->dh, node_attr, "type",
1173 index_type_str, zei->nmem);
1174 if (zsui->info.which == ZEB_SU_SET_USE)
1176 oident.proto = PROTO_Z3950;
1177 oident.oclass = CLASS_ATTSET;
1178 oident.value = (enum oid_value) zsui->info.u.su.set;
1179 oid_ent_to_oid (&oident, oid);
1181 data1_mk_tag_data_text (zei->dh, node_attr, "set",
1182 oident.desc, zei->nmem);
1183 data1_mk_tag_data_int (zei->dh, node_attr, "use",
1184 zsui->info.u.su.use, zei->nmem);
1186 else if (zsui->info.which == ZEB_SU_STR)
1188 data1_mk_tag_data_text (zei->dh, node_attr, "str",
1189 zsui->info.u.str, zei->nmem);
1191 data1_mk_tag_data_int (zei->dh, node_attr, "ordinal",
1192 zsui->info.ordinal, zei->nmem);
1194 data1_mk_tag_data_zint (zei->dh, node_attr, "dococcurrences",
1195 zsui->info.doc_occurrences, zei->nmem);
1196 data1_mk_tag_data_zint (zei->dh, node_attr, "termoccurrences",
1197 zsui->info.term_occurrences, zei->nmem);
1199 /* convert to "SGML" and write it */
1201 data1_pr_tree (zei->dh, zad->data1_tree, stderr);
1203 sgml_buf = data1_nodetoidsgml(zei->dh, zad->data1_tree,
1205 drec->info[recInfo_storeData] = (char *) xmalloc (sgml_len);
1206 memcpy (drec->info[recInfo_storeData], sgml_buf, sgml_len);
1207 drec->size[recInfo_storeData] = sgml_len;
1209 rec_put (zei->records, &drec);
1212 static void zebraExplain_writeDatabase (ZebraExplainInfo zei,
1213 struct zebDatabaseInfoB *zdi,
1219 data1_node *node_dbinfo, *node_count, *node_zebra;
1226 yaz_log(YLOG_LOG, "zebraExplain_writeDatabase %s", zdi->databaseName);
1228 drec = createRecord (zei->records, &zdi->sysno);
1231 assert (zdi->data1_database);
1233 node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database,
1236 assert (node_dbinfo);
1237 zebraExplain_updateCommonInfo (zei, node_dbinfo);
1238 zebraExplain_updateAccessInfo (zei, node_dbinfo, zdi->accessInfo);
1240 /* extract *searchable* keys from it. We do this here, because
1241 record count, etc. is affected */
1243 (*zei->updateFunc)(zei->updateHandle, drec, zdi->data1_database);
1245 node_count = data1_mk_tag_uni (zei->dh, zei->nmem,
1246 "recordCount", node_dbinfo);
1247 data1_mk_tag_data_zint (zei->dh, node_count, "recordCountActual",
1248 zdi->recordCount, zei->nmem);
1250 /* zebra info (private) */
1251 node_zebra = data1_mk_tag_uni (zei->dh, zei->nmem,
1252 "zebraInfo", node_dbinfo);
1253 data1_mk_tag_data_zint (zei->dh, node_zebra,
1254 "recordBytes", zdi->recordBytes, zei->nmem);
1256 data1_mk_tag_data_zint(zei->dh, node_zebra,
1257 "ordinalDatabase", zdi->ordinalDatabase, zei->nmem);
1259 /* convert to "SGML" and write it */
1261 data1_pr_tree (zei->dh, zdi->data1_database, stderr);
1263 sgml_buf = data1_nodetoidsgml(zei->dh, zdi->data1_database,
1265 drec->info[recInfo_storeData] = (char *) xmalloc (sgml_len);
1266 memcpy (drec->info[recInfo_storeData], sgml_buf, sgml_len);
1267 drec->size[recInfo_storeData] = sgml_len;
1269 rec_put (zei->records, &drec);
1272 static void writeAttributeValues (ZebraExplainInfo zei,
1273 data1_node *node_values,
1274 data1_attset *attset)
1277 data1_attset_child *c;
1282 for (c = attset->children; c; c = c->next)
1283 writeAttributeValues (zei, node_values, c->child);
1284 for (atts = attset->atts; atts; atts = atts->next)
1286 data1_node *node_value;
1288 node_value = data1_mk_tag (zei->dh, zei->nmem, "attributeValue",
1289 0 /* attr */, node_values);
1290 data1_mk_tag_data_text (zei->dh, node_value, "name",
1291 atts->name, zei->nmem);
1292 node_value = data1_mk_tag (zei->dh, zei->nmem, "value",
1293 0 /* attr */, node_value);
1294 data1_mk_tag_data_int (zei->dh, node_value, "numeric",
1295 atts->value, zei->nmem);
1300 static void zebraExplain_writeAttributeSet (ZebraExplainInfo zei,
1307 data1_node *node_root, *node_attinfo, *node_attributes, *node_atttype;
1308 data1_node *node_values;
1309 struct oident *entp;
1310 struct data1_attset *attset = NULL;
1312 if ((entp = oid_getentbyoid (o->oid)))
1313 attset = data1_attset_search_id (zei->dh, entp->value);
1316 yaz_log(YLOG_LOG, "zebraExplain_writeAttributeSet %s",
1317 attset ? attset->name : "<unknown>");
1320 drec = createRecord (zei->records, &o->sysno);
1324 data1_read_sgml (zei->dh, zei->nmem,
1325 "<explain><attributeSetInfo>AttributeSetInfo\n"
1328 node_attinfo = data1_search_tag (zei->dh, node_root,
1329 "/attributeSetInfo");
1331 assert (node_attinfo);
1332 zebraExplain_initCommonInfo (zei, node_attinfo);
1333 zebraExplain_updateCommonInfo (zei, node_attinfo);
1335 data1_mk_tag_data_oid (zei->dh, node_attinfo,
1336 "oid", o->oid, zei->nmem);
1337 if (attset && attset->name)
1338 data1_mk_tag_data_text (zei->dh, node_attinfo,
1339 "name", attset->name, zei->nmem);
1341 node_attributes = data1_mk_tag_uni (zei->dh, zei->nmem,
1342 "attributes", node_attinfo);
1343 node_atttype = data1_mk_tag_uni (zei->dh, zei->nmem,
1344 "attributeType", node_attributes);
1345 data1_mk_tag_data_text (zei->dh, node_atttype,
1346 "name", "Use", zei->nmem);
1347 data1_mk_tag_data_text (zei->dh, node_atttype,
1348 "description", "Use Attribute", zei->nmem);
1349 data1_mk_tag_data_int (zei->dh, node_atttype,
1350 "type", 1, zei->nmem);
1351 node_values = data1_mk_tag (zei->dh, zei->nmem,
1352 "attributeValues", 0 /* attr */, node_atttype);
1354 writeAttributeValues (zei, node_values, attset);
1356 /* extract *searchable* keys from it. We do this here, because
1357 record count, etc. is affected */
1359 (*zei->updateFunc)(zei->updateHandle, drec, node_root);
1360 /* convert to "SGML" and write it */
1362 data1_pr_tree (zei->dh, node_root, stderr);
1364 sgml_buf = data1_nodetoidsgml(zei->dh, node_root, 0, &sgml_len);
1365 drec->info[recInfo_storeData] = (char *) xmalloc (sgml_len);
1366 memcpy (drec->info[recInfo_storeData], sgml_buf, sgml_len);
1367 drec->size[recInfo_storeData] = sgml_len;
1369 rec_put (zei->records, &drec);
1372 static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush)
1374 struct zebDatabaseInfoB *zdi;
1375 data1_node *node_tgtinfo, *node_list, *node_zebra;
1384 trec = rec_get_root(zei->records);
1385 xfree (trec->info[recInfo_storeData]);
1387 node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target,
1389 assert (node_tgtinfo);
1391 zebraExplain_updateCommonInfo (zei, node_tgtinfo);
1392 zebraExplain_updateAccessInfo (zei, node_tgtinfo, zei->accessInfo);
1394 /* convert to "SGML" and write it */
1396 (*zei->updateFunc)(zei->updateHandle, trec, zei->data1_target);
1398 node_zebra = data1_mk_tag_uni (zei->dh, zei->nmem,
1399 "zebraInfo", node_tgtinfo);
1400 data1_mk_tag_data_text (zei->dh, node_zebra, "version",
1401 ZEBRAVER, zei->nmem);
1402 node_list = data1_mk_tag (zei->dh, zei->nmem,
1403 "databaseList", 0 /* attr */, node_zebra);
1404 for (zdi = zei->databaseInfo; zdi; zdi = zdi->next)
1406 data1_node *node_db;
1407 node_db = data1_mk_tag (zei->dh, zei->nmem,
1408 "database", 0 /* attr */, node_list);
1409 data1_mk_tag_data_text (zei->dh, node_db, "name",
1410 zdi->databaseName, zei->nmem);
1411 data1_mk_tag_data_zint (zei->dh, node_db, "id",
1412 zdi->sysno, zei->nmem);
1413 data1_mk_tag_data_zint (zei->dh, node_db, "attributeDetailsId",
1414 zdi->attributeDetails->sysno, zei->nmem);
1416 data1_mk_tag_data_int (zei->dh, node_zebra, "ordinalSU",
1417 zei->ordinalSU, zei->nmem);
1419 data1_mk_tag_data_int (zei->dh, node_zebra, "ordinalDatabase",
1420 zei->ordinalDatabase, zei->nmem);
1422 data1_mk_tag_data_zint (zei->dh, node_zebra, "runNumber",
1423 zei->runNumber, zei->nmem);
1426 data1_pr_tree (zei->dh, zei->data1_target, stderr);
1428 sgml_buf = data1_nodetoidsgml(zei->dh, zei->data1_target,
1430 trec->info[recInfo_storeData] = (char *) xmalloc (sgml_len);
1431 memcpy (trec->info[recInfo_storeData], sgml_buf, sgml_len);
1432 trec->size[recInfo_storeData] = sgml_len;
1434 rec_put (zei->records, &trec);
1437 int zebraExplain_lookup_attr_su_any_index(ZebraExplainInfo zei,
1440 struct zebSUInfoB *zsui;
1442 assert (zei->curDatabaseInfo);
1443 for (zsui = zei->curDatabaseInfo->attributeDetails->SUInfo;
1444 zsui; zsui=zsui->next)
1445 if (zsui->info.which == ZEB_SU_SET_USE &&
1446 zsui->info.u.su.use == use && zsui->info.u.su.set == set)
1447 return zsui->info.ordinal;
1451 int zebraExplain_lookup_attr_su(ZebraExplainInfo zei, int index_type,
1454 struct zebSUInfoB **zsui;
1457 yaz_log(YLOG_LOG, "lookup_attr_su index_type=%d set=%d use=%d",
1458 index_type, set, use);
1460 assert (zei->curDatabaseInfo);
1461 for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo;
1462 *zsui; zsui = &(*zsui)->next)
1463 if ((*zsui)->info.index_type == index_type &&
1464 (*zsui)->info.which == ZEB_SU_SET_USE &&
1465 (*zsui)->info.u.su.use == use && (*zsui)->info.u.su.set == set)
1467 struct zebSUInfoB *zsui_this = *zsui;
1469 /* take it out of the list and move to front */
1470 *zsui = (*zsui)->next;
1471 zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo;
1472 zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this;
1474 return zsui_this->info.ordinal;
1479 int zebraExplain_lookup_attr_str(ZebraExplainInfo zei, int index_type,
1482 struct zebSUInfoB **zsui;
1484 assert (zei->curDatabaseInfo);
1485 for (zsui = &zei->curDatabaseInfo->attributeDetails->SUInfo;
1486 *zsui; zsui = &(*zsui)->next)
1487 if ((*zsui)->info.index_type == index_type
1488 && (*zsui)->info.which == ZEB_SU_STR
1489 && !strcmp((*zsui)->info.u.str, str))
1491 struct zebSUInfoB *zsui_this = *zsui;
1493 /* take it out of the list and move to front */
1494 *zsui = (*zsui)->next;
1495 zsui_this->next = zei->curDatabaseInfo->attributeDetails->SUInfo;
1496 zei->curDatabaseInfo->attributeDetails->SUInfo = zsui_this;
1498 return zsui_this->info.ordinal;
1503 int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle,
1504 int (*f)(void *handle, int ord))
1506 struct zebDatabaseInfoB *zdb = zei->curDatabaseInfo;
1509 struct zebSUInfoB *zsui = zdb->attributeDetails->SUInfo;
1510 for ( ;zsui; zsui = zsui->next)
1511 (*f)(handle, zsui->info.ordinal);
1517 struct zebSUInfoB *zebraExplain_get_sui_info (ZebraExplainInfo zei, int ord,
1521 struct zebDatabaseInfoB *zdb;
1523 for (zdb = zei->databaseInfo; zdb; zdb = zdb->next)
1525 struct zebSUInfoB **zsui;
1527 if (zdb->attributeDetails->readFlag)
1528 zebraExplain_readAttributeDetails (zei, zdb->attributeDetails);
1530 for (zsui = &zdb->attributeDetails->SUInfo; *zsui;
1531 zsui = &(*zsui)->next)
1532 if ((*zsui)->info.ordinal == ord)
1534 struct zebSUInfoB *zsui_this = *zsui;
1536 /* take it out of the list and move to front */
1537 *zsui = (*zsui)->next;
1538 zsui_this->next = zdb->attributeDetails->SUInfo;
1539 zdb->attributeDetails->SUInfo = zsui_this;
1542 zdb->attributeDetails->dirty = 1;
1544 *db = zdb->databaseName;
1553 int zebraExplain_ord_adjust_occurrences(ZebraExplainInfo zei, int ord,
1554 int term_delta, int doc_delta)
1556 struct zebSUInfoB *zsui = zebraExplain_get_sui_info(zei, ord, 1, 0);
1559 zsui->info.term_occurrences += term_delta;
1560 zsui->info.doc_occurrences += doc_delta;
1566 int zebraExplain_ord_get_occurrences(ZebraExplainInfo zei, int ord,
1567 zint *term_occurrences,
1568 zint *doc_occurrences)
1570 struct zebSUInfoB *zsui = zebraExplain_get_sui_info(zei, ord, 0, 0);
1573 *term_occurrences = zsui->info.term_occurrences;
1574 *doc_occurrences = zsui->info.doc_occurrences;
1580 int zebraExplain_lookup_ord(ZebraExplainInfo zei, int ord,
1584 const char **string_index)
1586 struct zebSUInfoB *zsui;
1597 zsui = zebraExplain_get_sui_info(zei, ord, 0, db);
1600 if (zsui->info.which == ZEB_SU_SET_USE)
1603 *set = zsui->info.u.su.set;
1605 *use = zsui->info.u.su.use;
1608 if (zsui->info.which == ZEB_SU_STR)
1610 *string_index = zsui->info.u.str;
1613 *index_type = zsui->info.index_type;
1621 zebAccessObject zebraExplain_announceOid (ZebraExplainInfo zei,
1622 zebAccessObject *op,
1627 for (ao = *op; ao; ao = ao->next)
1628 if (!oid_oidcmp (oid, ao->oid))
1632 ao = (zebAccessObject) nmem_malloc (zei->nmem, sizeof(*ao));
1635 ao->oid = odr_oiddup_nmem (zei->nmem, oid);
1642 void zebraExplain_addAttributeSet (ZebraExplainInfo zei, int set)
1647 oe.proto = PROTO_Z3950;
1648 oe.oclass = CLASS_ATTSET;
1649 oe.value = (enum oid_value) set;
1651 if (oid_ent_to_oid (&oe, oid))
1653 zebraExplain_announceOid (zei, &zei->accessInfo->attributeSetIds, oid);
1654 zebraExplain_announceOid (zei, &zei->curDatabaseInfo->
1655 accessInfo->attributeSetIds, oid);
1659 struct zebSUInfoB *zebraExplain_add_sui_info(ZebraExplainInfo zei,
1662 struct zebSUInfoB *zsui;
1664 assert (zei->curDatabaseInfo);
1665 zsui = (struct zebSUInfoB *) nmem_malloc (zei->nmem, sizeof(*zsui));
1666 zsui->next = zei->curDatabaseInfo->attributeDetails->SUInfo;
1667 zei->curDatabaseInfo->attributeDetails->SUInfo = zsui;
1668 zei->curDatabaseInfo->attributeDetails->dirty = 1;
1670 zsui->info.index_type = index_type;
1671 zsui->info.doc_occurrences = 0;
1672 zsui->info.term_occurrences = 0;
1673 zsui->info.ordinal = (zei->ordinalSU)++;
1677 int zebraExplain_add_attr_su(ZebraExplainInfo zei, int index_type,
1680 struct zebSUInfoB *zsui = zebraExplain_add_sui_info(zei, index_type);
1682 zebraExplain_addAttributeSet (zei, set);
1683 zsui->info.which = ZEB_SU_SET_USE;
1684 zsui->info.u.su.set = set;
1685 zsui->info.u.su.use = use;
1686 return zsui->info.ordinal;
1689 int zebraExplain_add_attr_str(ZebraExplainInfo zei, int index_type,
1690 const char *index_name)
1692 struct zebSUInfoB *zsui = zebraExplain_add_sui_info(zei, index_type);
1694 zsui->info.which = ZEB_SU_STR;
1695 zsui->info.u.str = nmem_strdup(zei->nmem, index_name);
1696 return zsui->info.ordinal;
1699 void zebraExplain_addSchema (ZebraExplainInfo zei, Odr_oid *oid)
1701 zebraExplain_announceOid (zei, &zei->accessInfo->schemas, oid);
1702 zebraExplain_announceOid (zei, &zei->curDatabaseInfo->
1703 accessInfo->schemas, oid);
1706 void zebraExplain_recordBytesIncrement (ZebraExplainInfo zei, int adjust_num)
1708 assert (zei->curDatabaseInfo);
1712 zei->curDatabaseInfo->recordBytes += adjust_num;
1713 zei->curDatabaseInfo->dirty = 1;
1717 void zebraExplain_recordCountIncrement (ZebraExplainInfo zei, int adjust_num)
1719 assert (zei->curDatabaseInfo);
1723 zei->curDatabaseInfo->recordCount += adjust_num;
1724 zei->curDatabaseInfo->dirty = 1;
1728 zint zebraExplain_runNumberIncrement (ZebraExplainInfo zei, int adjust_num)
1734 return zei->runNumber += adjust_num;
1737 RecordAttr *rec_init_attr (ZebraExplainInfo zei, Record rec)
1739 RecordAttr *recordAttr;
1741 if (rec->info[recInfo_attr])
1742 return (RecordAttr *) rec->info[recInfo_attr];
1743 recordAttr = (RecordAttr *) xmalloc (sizeof(*recordAttr));
1744 rec->info[recInfo_attr] = (char *) recordAttr;
1745 rec->size[recInfo_attr] = sizeof(*recordAttr);
1747 recordAttr->recordSize = 0;
1748 recordAttr->recordOffset = 0;
1749 recordAttr->runNumber = zei->runNumber;
1750 recordAttr->staticrank = 0;
1754 static void att_loadset(void *p, const char *n, const char *name)
1756 data1_handle dh = (data1_handle) p;
1757 if (!data1_get_attset (dh, name))
1758 yaz_log(YLOG_WARN, "Directive attset failed for %s", name);
1761 int zebraExplain_get_database_ord(ZebraExplainInfo zei)
1763 if (!zei->curDatabaseInfo)
1765 return zei->curDatabaseInfo->ordinalDatabase;
1768 void zebraExplain_loadAttsets (data1_handle dh, Res res)
1770 res_trav(res, "attset", dh, att_loadset);
1774 zebraExplain_addSU adds to AttributeDetails for a database and
1775 adds attributeSet (in AccessInfo area) to DatabaseInfo if it doesn't
1776 exist for the database.
1778 If the database doesn't exist globally (in TargetInfo) an
1779 AttributeSetInfo must be added (globally).
1784 * indent-tabs-mode: nil
1786 * vim: shiftwidth=4 tabstop=8 expandtab