+Z_FacetTerm *yaz_sru_proxy_get_facet_term_count(ODR odr, xmlNodePtr node) {
+
+ int freq;
+ xmlNodePtr child;
+ WRBUF wrbuf = wrbuf_alloc();
+ const char *freq_string = yaz_element_attribute_value_get(node, "facetvalue", "est_representation");
+ Z_Term *term;
+ if (freq_string)
+ freq = atoi(freq_string);
+ else
+ freq = -1;
+
+ for (child = node->children; child ; child = child->next) {
+ if (child->type == XML_TEXT_NODE)
+ wrbuf_puts(wrbuf, (const char *) child->content);
+ }
+ term = term_create(odr, wrbuf_cstr(wrbuf));
+ yaz_log(YLOG_DEBUG, "sru-proxy facet: %s %d", wrbuf_cstr(wrbuf), freq);
+ wrbuf_destroy(wrbuf);
+ return facet_term_create(odr, term, freq);
+};
+
+static Z_FacetField *yaz_sru_proxy_decode_facet_field(ODR odr, xmlNodePtr ptr) {
+ Z_AttributeList *list;
+ Z_FacetField *facet_field;
+ int num_terms = 0;
+ int index = 0;
+ xmlNodePtr node;
+ // USE attribute
+ const char* name = yaz_element_attribute_value_get(ptr, "facet", "code");
+ yaz_log(YLOG_DEBUG, "sru-proxy facet type: %s", name);
+
+ list = yaz_use_atttribute_create(odr, name);
+ for (node = ptr->children; node; node = node->next) {
+ if (match_element(node, "facetvalue"))
+ num_terms++;
+ }
+ facet_field = facet_field_create(odr, list, num_terms);
+ index = 0;
+ for (node = ptr->children; node; node = node->next) {
+ if (match_element(node, "facetvalue")) {
+ facet_field_term_set(odr, facet_field, yaz_sru_proxy_get_facet_term_count(odr, node), index);
+ index++;
+ }
+ }
+ return facet_field;
+}
+
+static int yaz_sru_proxy_decode_facets(ODR o, xmlNodePtr root, Z_FacetList **facetList)