1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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
26 #include <yaz/diagbib1.h>
27 #include <idzebra/res.h>
28 #include <idzebra/util.h>
31 #include <yaz/oid_db.h>
33 static data1_att *getatt(data1_attset *p, int att)
36 data1_attset_child *c;
39 for (a = p->atts; a; a = a->next)
42 /* scan included sets */
43 for (c = p->children; c; c = c->next)
44 if ((a = getatt(c->child, att)))
49 static int att_getentbyatt(ZebraHandle zi, const Odr_oid *set, int att,
55 if (!(p = data1_attset_search_id (zi->reg->dh, set)))
57 zebraExplain_loadAttsets (zi->reg->dh, zi->res);
58 p = data1_attset_search_id (zi->reg->dh, set);
60 if (!p) /* set undefined */
62 if (!(r = getatt(p, att)))
69 ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
70 Z_AttributeList *attr_list,
71 zinfo_index_category_t cat,
72 const char *index_type,
73 const Odr_oid *curAttributeSet,
77 const char *use_string = 0;
80 attr_init_AttrList(&use, attr_list, 1);
81 use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
90 /* we have a use attribute and attribute set */
93 r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
96 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
101 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
107 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
110 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
111 index_type, use_string);
114 /* attribute 14=1 does not issue a diagnostic even
115 1) the attribute is numeric but listed in .att
116 2) the use attribute is string
120 attr_init_AttrList(&unsup, attr_list, 14);
121 unsup_value = attr_find(&unsup, 0);
123 if (unsup_value != 1)
126 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_string);
128 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
135 ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
136 Z_AttributesPlusTerm *zapt,
137 const char *index_type,
138 const char *xpath_use,
139 const Odr_oid *curAttributeSet,
142 ZEBRA_RES res = ZEBRA_OK;
145 zinfo_index_category_t cat = zinfo_index_category_index;
147 attr_init_APT(&relation, zapt, 2);
148 relation_value = attr_find(&relation, NULL);
150 if (relation_value == 103) /* always matches */
151 cat = zinfo_index_category_alwaysmatches;
155 res = zebra_attr_list_get_ord(zh, zapt->attributes,
157 curAttributeSet, ord);
158 /* use attribute not found. But it the relation is
159 always matches and the regulare index attribute is found
160 return a different diagnostic */
161 if (res != ZEBRA_OK &&
162 relation_value == 103
163 && zebra_attr_list_get_ord(
164 zh, zapt->attributes,
165 zinfo_index_category_index, index_type,
166 curAttributeSet, ord) == ZEBRA_OK)
167 zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
171 *ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat, index_type,
175 yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%s",
176 xpath_use, index_type);
177 zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
182 yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%s",
183 xpath_use, index_type);
190 ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
191 Z_SortAttributes *sortAttributes,
198 attr_init_AttrList(&structure, sortAttributes->list, 4);
201 structure_value = attr_find(&structure, 0);
202 if (structure_value == 109)
205 if (zebra_attr_list_get_ord(
206 zh, sortAttributes->list,
207 zinfo_index_category_sort,
208 0 /* any index */, yaz_oid_attset_bib_1, ord) == ZEBRA_OK)
217 * c-file-style: "Stroustrup"
218 * indent-tabs-mode: nil
220 * vim: shiftwidth=4 tabstop=8 expandtab