1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/diagbib1.h>
24 #include <idzebra/res.h>
25 #include <idzebra/util.h>
28 #include <yaz/oid_db.h>
30 static data1_att *getatt(data1_attset *p, int att)
33 data1_attset_child *c;
36 for (a = p->atts; a; a = a->next)
39 /* scan included sets */
40 for (c = p->children; c; c = c->next)
41 if ((a = getatt(c->child, att)))
46 static int att_getentbyatt(ZebraHandle zi, const Odr_oid *set, int att,
52 if (!(p = data1_attset_search_id (zi->reg->dh, set)))
54 zebraExplain_loadAttsets (zi->reg->dh, zi->res);
55 p = data1_attset_search_id (zi->reg->dh, set);
57 if (!p) /* set undefined */
59 if (!(r = getatt(p, att)))
66 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
67 Z_AttributeList *attr_list,
68 zinfo_index_category_t cat,
69 const char *index_type,
70 const Odr_oid *curAttributeSet,
74 const char *use_string = 0;
77 attr_init_AttrList(&use, attr_list, 1);
78 use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
87 /* we have a use attribute and attribute set */
90 r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
93 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
98 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
104 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
107 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
108 index_type, use_string);
111 /* attribute 14=1 does not issue a diagnostic even
112 1) the attribute is numeric but listed in .att
113 2) the use attribute is string
117 attr_init_AttrList(&unsup, attr_list, 14);
118 unsup_value = attr_find(&unsup, 0);
120 if (unsup_value != 1)
123 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_string);
125 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
132 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
133 Z_AttributesPlusTerm *zapt,
134 const char *index_type,
135 const char *xpath_use,
136 const Odr_oid *curAttributeSet,
139 ZEBRA_RES res = ZEBRA_OK;
142 zinfo_index_category_t cat = zinfo_index_category_index;
144 attr_init_APT(&relation, zapt, 2);
145 relation_value = attr_find(&relation, NULL);
147 if (relation_value == 103) /* always matches */
148 cat = zinfo_index_category_alwaysmatches;
152 res = zebra_attr_list_get_ord(zh, zapt->attributes,
154 curAttributeSet, ord);
155 /* use attribute not found. But it the relation is
156 always matches and the regulare index attribute is found
157 return a different diagnostic */
158 if (res != ZEBRA_OK &&
159 relation_value == 103
160 && zebra_attr_list_get_ord(
161 zh, zapt->attributes,
162 zinfo_index_category_index, index_type,
163 curAttributeSet, ord) == ZEBRA_OK)
164 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
168 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat, index_type,
172 yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%s",
173 xpath_use, index_type);
174 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
179 yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%s",
180 xpath_use, index_type);
187 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
188 Z_SortAttributes *sortAttributes,
195 attr_init_AttrList(&structure, sortAttributes->list, 4);
198 structure_value = attr_find(&structure, 0);
199 if (structure_value == 109)
202 if (zebra_attr_list_get_ord(
203 zh, sortAttributes->list,
204 zinfo_index_category_sort,
205 0 /* any index */, yaz_oid_attset_bib_1, ord) == ZEBRA_OK)
214 * c-file-style: "Stroustrup"
215 * indent-tabs-mode: nil
217 * vim: shiftwidth=4 tabstop=8 expandtab