+ ztest_sleep(d);
+ }
+}
+
+static void addterms(ODR odr, Z_FacetField *facet_field, const char *facet_name)
+{
+ int index;
+ int freq = 100;
+ int length = strlen(facet_name) + 10;
+ char *key = odr_malloc(odr, length);
+ key[0] = '\0';
+ for (index = 0; index < facet_field->num_terms; index++)
+ {
+ Z_FacetTerm *facet_term;
+ sprintf(key, "%s%d", facet_name, index);
+ yaz_log(YLOG_DEBUG, "facet add term %s %d %s", facet_name, index, key);
+
+ facet_term = facet_term_create_cstr(odr, key, freq);
+ freq = freq - 10 ;
+ facet_field_term_set(odr, facet_field, facet_term, index);
+ }
+}
+
+Z_OtherInformation *build_facet_response(ODR odr, Z_FacetList *facet_list) {
+ int index, new_index = 0;
+ Z_FacetList *new_list = facet_list_create(odr, facet_list->num);
+
+ for (index = 0; index < facet_list->num; index++) {
+ struct yaz_facet_attr attrvalues;
+ yaz_facet_attr_init(&attrvalues);
+ attrvalues.limit = 10;
+ yaz_facet_attr_get_z_attributes(facet_list->elements[index]->attributes,
+ &attrvalues);
+ yaz_log(YLOG_LOG, "Attributes: %s limit=%d start=%d sort=%d",
+ attrvalues.useattr ? attrvalues.useattr : "NONE",
+ attrvalues.limit,
+ attrvalues.start,
+ attrvalues.sortorder);
+ if (attrvalues.errstring)
+ yaz_log(YLOG_LOG, "Error parsing attributes: %s", attrvalues.errstring);
+ if (attrvalues.limit > 0 && attrvalues.useattr) {
+ new_list->elements[new_index] = facet_field_create(odr, facet_list->elements[index]->attributes, attrvalues.limit);
+ addterms(odr, new_list->elements[new_index], attrvalues.useattr);
+ new_index++;
+ }
+ else {
+ yaz_log(YLOG_DEBUG, "Facet: skipping %s due to 0 limit.", attrvalues.useattr);
+ }
+