+ *pdup = pdu;
+ return ret;
+}
+
+static int yaz_solr_encode_facet_field(
+ ODR encode, char **name, char **value, int *i,
+ Z_FacetField *facet_field)
+{
+ Z_AttributeList *attribute_list = facet_field->attributes;
+ struct yaz_facet_attr attr_values;
+ yaz_facet_attr_init(&attr_values);
+ yaz_facet_attr_get_z_attributes(attribute_list, &attr_values);
+
+ if (attr_values.errcode)
+ return -1;
+ if (attr_values.useattr)
+ {
+ WRBUF wrbuf = wrbuf_alloc();
+ yaz_add_name_value_str(encode, name, value, i,
+ "facet.field",
+ odr_strdup(encode, attr_values.useattr));
+
+ if (attr_values.limit > 0)
+ {
+ Odr_int v = attr_values.limit;
+ wrbuf_rewind(wrbuf);
+ wrbuf_printf(wrbuf, "f.%s.facet.limit", attr_values.useattr);
+ yaz_add_name_value_int(encode, name, value, i,
+ odr_strdup(encode, wrbuf_cstr(wrbuf)),
+ &v);
+ }
+ if (attr_values.start > 1)
+ {
+ Odr_int v = attr_values.start - 1;
+ wrbuf_rewind(wrbuf);
+ wrbuf_printf(wrbuf, "f.%s.facet.offset", attr_values.useattr);
+ yaz_add_name_value_int(encode, name, value, i,
+ odr_strdup(encode, wrbuf_cstr(wrbuf)),
+ &v);
+ }
+ if (attr_values.sortorder == 1)
+ {
+ wrbuf_rewind(wrbuf);
+ wrbuf_printf(wrbuf, "f.%s.facet.sort", attr_values.useattr);
+ yaz_add_name_value_str(encode, name, value, i,
+ odr_strdup(encode, wrbuf_cstr(wrbuf)),
+ "index");
+ }
+ wrbuf_destroy(wrbuf);
+ }
+ else
+ {
+ if (attr_values.limit > 0)
+ {
+ Odr_int v = attr_values.limit;
+ yaz_add_name_value_int(encode, name, value, i, "facet.limit", &v);
+ }
+ if (attr_values.start > 1)
+ {
+ Odr_int v = attr_values.start - 1;
+ yaz_add_name_value_int(encode, name, value, i, "facet.offset", &v);
+ }
+ if (attr_values.sortorder == 1)
+ {
+ yaz_add_name_value_str(encode, name, value, i, "facet.sort",
+ "index");
+ }
+ }
+ return 0;
+}
+
+static int yaz_solr_encode_facet_list(
+ ODR encode, char **name, char **value,
+ int *i, Z_FacetList *facet_list)
+{
+ int index;
+ for (index = 0; index < facet_list->num; index++)
+ {
+ int r = yaz_solr_encode_facet_field(encode, name, value, i,
+ facet_list->elements[index]);
+ if (r)
+ return -1;
+
+ }
+ return 0;