1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
/* This file is part of the Zebra server.
Copyright (C) Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <yaz/log.h>
#include <yaz/diagbib1.h>
#include <idzebra/res.h>
#include <idzebra/util.h>
#include <attrfind.h>
#include "index.h"
#include <yaz/oid_db.h>
static data1_att *getatt(data1_attset *p, int att)
{
data1_att *a;
data1_attset_child *c;
/* scan local set */
for (a = p->atts; a; a = a->next)
if (a->value == att)
return a;
/* scan included sets */
for (c = p->children; c; c = c->next)
if ((a = getatt(c->child, att)))
return a;
return 0;
}
static int att_getentbyatt(ZebraHandle zi, const Odr_oid *set, int att,
const char **name)
{
data1_att *r;
data1_attset *p;
if (!(p = data1_attset_search_id (zi->reg->dh, set)))
{
zebraExplain_loadAttsets (zi->reg->dh, zi->res);
p = data1_attset_search_id (zi->reg->dh, set);
}
if (!p) /* set undefined */
return -2;
if (!(r = getatt(p, att)))
return -1;
*name = r->name;
return 0;
}
ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh,
Z_AttributeList *attr_list,
zinfo_index_category_t cat,
const char *index_type,
const Odr_oid *curAttributeSet,
int *ord)
{
int use_value = -1;
const char *use_string = 0;
AttrType use;
attr_init_AttrList(&use, attr_list, 1);
use_value = attr_find_ex(&use, &curAttributeSet, &use_string);
if (use_value < 0)
{
if (!use_string)
use_string = "any";
}
else
{
/* we have a use attribute and attribute set */
int r;
r = att_getentbyatt(zh, curAttributeSet, use_value, &use_string);
if (r == -2)
{
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_ATTRIBUTE_SET, 0);
return ZEBRA_FAIL;
}
if (r == -1)
{
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
return ZEBRA_FAIL;
}
}
if (!use_string)
{
zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
return ZEBRA_FAIL;
}
*ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
index_type, use_string);
if (*ord == -1)
{
/* attribute 14=1 does not issue a diagnostic even
1) the attribute is numeric but listed in .att
2) the use attribute is string
*/
AttrType unsup;
int unsup_value = 0;
attr_init_AttrList(&unsup, attr_list, 14);
unsup_value = attr_find(&unsup, 0);
if (unsup_value != 1)
{
if (use_value < 0)
zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_string);
else
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, use_value);
return ZEBRA_FAIL;
}
}
return ZEBRA_OK;
}
ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const char *index_type,
const char *xpath_use,
const Odr_oid *curAttributeSet,
int *ord)
{
ZEBRA_RES res = ZEBRA_OK;
AttrType relation;
int relation_value;
zinfo_index_category_t cat = zinfo_index_category_index;
attr_init_APT(&relation, zapt, 2);
relation_value = attr_find(&relation, NULL);
if (relation_value == 103) /* always matches */
cat = zinfo_index_category_alwaysmatches;
if (!xpath_use)
{
res = zebra_attr_list_get_ord(zh, zapt->attributes,
cat, index_type,
curAttributeSet, ord);
/* use attribute not found. But it the relation is
always matches and the regulare index attribute is found
return a different diagnostic */
if (res != ZEBRA_OK &&
relation_value == 103
&& zebra_attr_list_get_ord(
zh, zapt->attributes,
zinfo_index_category_index, index_type,
curAttributeSet, ord) == ZEBRA_OK)
zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE, 103);
}
else
{
*ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat, index_type,
xpath_use);
if (*ord == -1)
{
yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%s",
xpath_use, index_type);
zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0);
res = ZEBRA_FAIL;
}
else
{
yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%s",
xpath_use, index_type);
}
}
return res;
}
ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh,
Z_SortAttributes *sortAttributes,
int *ord,
int *numerical)
{
AttrType structure;
int structure_value;
attr_init_AttrList(&structure, sortAttributes->list, 4);
*numerical = 0;
structure_value = attr_find(&structure, 0);
if (structure_value == 109)
*numerical = 1;
if (zebra_attr_list_get_ord(
zh, sortAttributes->list,
zinfo_index_category_sort,
0 /* any index */, yaz_oid_attset_bib_1, ord) == ZEBRA_OK)
return ZEBRA_OK;
return ZEBRA_FAIL;
}
/*
* Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
|