X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fattribute.c;h=10b1e6d968c69ee4e2416a327d7b729f7080d3ff;hb=b8d5d7476807b64d1c197efd9710cd4f5291152c;hp=78af3c15e6f407e16e4dcaa9f866cb2dd59ce523;hpb=c0c85097014e5b007075ab71d9b5bee412e28dd5;p=idzebra-moved-to-github.git diff --git a/index/attribute.c b/index/attribute.c index 78af3c1..10b1e6d 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -1,91 +1,181 @@ -/* - * Copyright (C) 1994-1995, Index Data I/S - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: attribute.c,v $ - * Revision 1.5 1997-09-05 15:30:08 adam - * Changed prototype for chr_map_input - added const. - * Added support for C++, headers uses extern "C" for public definitions. - * - * Revision 1.4 1996/10/29 14:06:48 adam - * Include zebrautl.h instead of alexutil.h. - * - * Revision 1.3 1996/05/09 07:28:54 quinn - * Work towards phrases and multiple registers - * - * Revision 1.2 1995/11/15 19:13:07 adam - * Work on record management. - * - * - * This interface is used by other modules (the Z-server in particular) - * to normalize the attributes given in queries. - */ +/* $Id: attribute.c,v 1.23 2006-05-19 13:49:34 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS + +This file is part of the Zebra server. + +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 Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ #include -#include -#include -#include -#include -#include "attribute.h" +#include +#include +#include +#include +#include +#include "index.h" -static int initialized = 0; +static data1_att *getatt(data1_attset *p, int att) +{ + data1_att *a; + data1_attset_child *c; -static data1_attset *registered_sets = 0; + /* 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 void att_loadset(const char *n, const char *name) +static int att_getentbyatt(ZebraHandle zi, oid_value set, int att, + const char **name) { - data1_attset *cnew; + data1_att *r; + data1_attset *p; - if (!(cnew = data1_read_attset((char*) name))) + if (!(p = data1_attset_search_id (zi->reg->dh, set))) { - logf(LOG_WARN|LOG_ERRNO, "%s", name); - return; + zebraExplain_loadAttsets (zi->reg->dh, zi->res); + p = data1_attset_search_id (zi->reg->dh, set); } - cnew->next = registered_sets; - registered_sets = cnew; + if (!p) /* set undefined */ + return -2; + if (!(r = getatt(p, att))) + return -1; + *name = r->name; + return 0; } -static void load_atts() -{ - res_trav(common_resource, "attset", att_loadset); -} -static data1_att *getatt(data1_attset *p, int att) +ZEBRA_RES zebra_attr_list_get_ord(ZebraHandle zh, + Z_AttributeList *attr_list, + int index_type, + oid_value curAttributeSet, + int *ord) { - data1_att *a; + 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); - for (; p; p = p->next) + if (use_value < 0) { - /* scan local set */ - for (a = p->atts; a; a = a->next) - if (a->value == att) - return a; - /* scan included sets */ - if (p->children && (a = getatt(p->children, att))) - return a; + if (!use_string) + use_string = "any"; } - return 0; + 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, index_type, use_string); + if (*ord == -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; } -attent *att_getentbyatt(oid_value set, int att) +ZEBRA_RES zebra_apt_get_ord(ZebraHandle zh, + Z_AttributesPlusTerm *zapt, + int index_type, + const char *xpath_use, + oid_value curAttributeSet, + int *ord) { - static attent res; - data1_att *r; - data1_attset *p; - - if (!initialized) + if (!xpath_use) + return zebra_attr_list_get_ord(zh, zapt->attributes, + index_type, curAttributeSet, ord); + else { - initialized = 1; - load_atts(); + *ord = zebraExplain_lookup_attr_str(zh->reg->zei, index_type, + xpath_use); + if (*ord == -1) + { + yaz_log(YLOG_LOG, "zebra_apt_get_ord FAILED xpath=%s index_type=%c", + xpath_use, index_type); + zebra_setError(zh, YAZ_BIB1_UNSUPP_USE_ATTRIBUTE, 0); + return ZEBRA_FAIL; + } + else + { + yaz_log(YLOG_LOG, "zebra_apt_get_ord OK xpath=%s index_type=%c", + xpath_use, index_type); + } + return ZEBRA_OK; } - for (p = registered_sets; p; p = p->next) - if (p->reference == set && (r = getatt(p, att))) - break;; - if (!p) - return 0; - res.attset_ordinal = r->parent->ordinal; - res.local_attributes = r->locals; - 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, + 's', VAL_BIB1, ord)== ZEBRA_OK) + return ZEBRA_OK; + if (zebra_attr_list_get_ord(zh, sortAttributes->list, + 'S', VAL_BIB1, ord)== ZEBRA_OK) + return ZEBRA_OK; + return ZEBRA_FAIL; +} + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +