X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ffacet.c;h=d32fcf69d5bc8d2b24015934dd64de1302e92bff;hp=a9d1ef993da4a9415a1cc16960e4033aaaec5e5f;hb=51e1ca7946289042c3c09e92afc1c1c465f5d870;hpb=0c46d2e66bdeea1600e700124a81a5d0a65d349e diff --git a/src/facet.c b/src/facet.c index a9d1ef9..d32fcf6 100644 --- a/src/facet.c +++ b/src/facet.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -43,17 +43,21 @@ void yaz_oi_set_facetlist( Z_FacetList *yaz_oi_get_facetlist(Z_OtherInformation **otherInformation) { - int categoryValue = 1; - Z_External *z_external = 0; - Z_OtherInformationUnit *oi = - yaz_oi_update(otherInformation, 0, yaz_oid_userinfo_facet_1, - categoryValue, 0); - if (!oi) - return 0; - z_external = oi->information.externallyDefinedInfo; - - if (z_external && z_external->which == Z_External_userFacets) - return z_external->u.facetList; + Z_OtherInformation *oi = *otherInformation; + if (oi) + { + int i; + for (i = 0; i < oi->num_elements; i++) + { + Z_OtherInformationUnit *oiu = oi->list[i]; + if (oiu->which == Z_OtherInfo_externallyDefinedInfo + && oiu->information.externallyDefinedInfo->which == + Z_External_userFacets) + { + return oiu->information.externallyDefinedInfo->u.facetList; + } + } + } return 0; } @@ -65,10 +69,11 @@ void yaz_facet_attr_init(struct yaz_facet_attr *attr_values) { attr_values->errcode = 0; attr_values->errstring = 0; - attr_values->relation = 0; + attr_values->sortorder = 0; attr_values->useattr = 0; attr_values->useattrbuff[0] = 0; attr_values->limit = 0; + attr_values->start = 0; } static const char *stringattr(Z_ComplexAttribute *c) @@ -115,41 +120,17 @@ static void useattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) } -static void sortorderattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) -{ - if (ae->which == Z_AttributeValue_numeric) - { - if (*ae->value.numeric == 0) - av->relation = "desc"; - else if (*ae->value.numeric == 1) - av->relation = "asc"; - else if (*ae->value.numeric == 3) - av->relation = "unknown/unordered"; - else - { - av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; - sprintf(av->useattrbuff, ODR_INT_PRINTF, - *ae-> attributeType); - av->errstring = av->useattrbuff; - } - } - else - { - av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; - av->errstring = "non-numeric relation attribute"; - } -} - -static void limitattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) +static void numattr(Z_AttributeElement *ae, struct yaz_facet_attr *av, + int *v) { if (ae->which == Z_AttributeValue_numeric) { - av->limit = *ae->value.numeric; + *v = *ae->value.numeric; } else { av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE; - av->errstring = "non-numeric limit attribute"; + av->errstring = "non-numeric limit/sort/start attribute"; } } @@ -177,12 +158,16 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, useattr(ae, av); } else if (*ae->attributeType == 2) - { /* sortorder */ - sortorderattr(ae, av); + { + numattr(ae, av, &av->sortorder); } else if (*ae->attributeType == 3) - { /* limit */ - limitattr(ae, av); + { + numattr(ae, av, &av->limit); + } + else if (*ae->attributeType == 4) + { + numattr(ae, av, &av->start); } else { /* unknown attribute */ @@ -190,7 +175,8 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, sprintf(av->useattrbuff, ODR_INT_PRINTF, *ae-> attributeType); av->errstring = av->useattrbuff; - yaz_log(YLOG_WARN, "Unsupported attribute type %s", av->useattrbuff); + yaz_log(YLOG_WARN, "Unsupported attribute type %s", + av->useattrbuff); /* would like to give a better message, but the standard */ /* tells me to return the attribute type */ } @@ -198,27 +184,8 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, return; /* no need to dig deeper, return on first error */ } return; -} /* facetattrs */ - -#if 0 -Z_Term *term_create(ODR odr, const char *cstr) -{ - Z_Term *term = odr_malloc(odr, sizeof(*term)); - term->which = Z_Term_characterString; - term->u.characterString = odr_strdup(odr, cstr); - return term; } -Z_FacetTerm* facet_term_create(ODR odr, Z_Term *term, int freq) -{ - Z_FacetTerm *facet_term = odr_malloc(odr, sizeof(*facet_term)); - facet_term->count = odr_malloc(odr, sizeof(*facet_term->count)); - facet_term->term = term; - *facet_term->count = freq; - return facet_term; -} -#endif - Z_FacetTerm *facet_term_create_cstr(ODR odr, const char *cstr, Odr_int freq) { Z_FacetTerm *facet_term = odr_malloc(odr, sizeof(*facet_term));