X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ffacet.c;h=40b5e1c29dd4fe5a14f5fe789f3eda406bfdeba9;hp=b83972c323cdd3f62e637b0e57fabc6ab6042547;hb=d2ed898832ae354c17254ff52c70c92278518efe;hpb=43a9d38d20c1b1bcd1a03b2445a501d27526bd35 diff --git a/src/facet.c b/src/facet.c index b83972c..40b5e1c 100644 --- a/src/facet.c +++ b/src/facet.c @@ -1,9 +1,9 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2011 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ -/** +/** * \file facet.c * \brief Facet utilities */ @@ -17,6 +17,7 @@ #include #include #include +#include #include void yaz_oi_set_facetlist( @@ -42,17 +43,20 @@ 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; } @@ -91,7 +95,6 @@ static void useattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) if (ae->which == Z_AttributeValue_complex) { s = stringattr(ae->value.complex); - yaz_log(YLOG_DEBUG, "useattr %s %s", s, av->useattr); if (s) { if (!av->useattr) @@ -113,25 +116,24 @@ static void useattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) sprintf(av->useattrbuff, ODR_INT_PRINTF, *ae->value.numeric); av->useattr = av->useattrbuff; } -} /* useattr */ +} -/* TODO rename to sortorder attr */ -static void relationattr(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 = "asc"; + else if (*ae->value.numeric == 3) av->relation = "unknown/unordered"; - } else { + else + { av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; sprintf(av->useattrbuff, ODR_INT_PRINTF, - *ae-> attributeType); + *ae-> attributeType); av->errstring = av->useattrbuff; } } @@ -140,21 +142,20 @@ static void relationattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) av->errcode = YAZ_BIB1_UNSUPP_RELATION_ATTRIBUTE; av->errstring = "non-numeric relation attribute"; } -} /* relationattr */ +} static void limitattr(Z_AttributeElement *ae, struct yaz_facet_attr *av) { if (ae->which == Z_AttributeValue_numeric) { av->limit = *ae->value.numeric; - yaz_log(YLOG_DEBUG, "limitattr %d ", av->limit); } else { av->errcode = YAZ_BIB1_UNSUPP_ATTRIBUTE; av->errstring = "non-numeric limit attribute"; } -} /* relationattr */ +} /* Get the index to be searched from the attributes. @attr 1 @@ -171,19 +172,17 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, { int i; Z_AttributeElement *ae; - yaz_log(YLOG_DEBUG, "Attribute num attributes: %d", - attributes->num_attributes); - for (i=0; i < attributes->num_attributes; i++) { + for (i = 0; i < attributes->num_attributes; i++) + { ae = attributes->attributes[i]; /* ignoring the attributeSet here */ - yaz_log(YLOG_DEBUG, "Attribute type %d", (int) *ae->attributeType); if (*ae->attributeType == 1) { /* use attribute */ useattr(ae, av); } else if (*ae->attributeType == 2) { /* sortorder */ - relationattr(ae, av); + sortorderattr(ae, av); } else if (*ae->attributeType == 3) { /* limit */ @@ -195,7 +194,7 @@ 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_DEBUG, "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 */ } @@ -205,6 +204,7 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, return; } /* facetattrs */ +#if 0 Z_Term *term_create(ODR odr, const char *cstr) { Z_Term *term = odr_malloc(odr, sizeof(*term)); @@ -221,6 +221,16 @@ Z_FacetTerm* facet_term_create(ODR odr, Z_Term *term, int freq) *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)); + Z_Term *term = z_Term_create(odr, Z_Term_general, cstr, strlen(cstr)); + facet_term->term = term; + facet_term->count = odr_intdup(odr, freq); + return facet_term; +} Z_FacetField* facet_field_create(ODR odr, Z_AttributeList *attributes, int num_terms)