+ else /* attempt to deduce structure */
+ {
+ const char *syntax = ZOOM_record_get(rec, "syntax", NULL);
+ if (syntax)
+ {
+ if (!strcmp(syntax, "XML"))
+ {
+ strcpy(type, "xml");
+ return 0;
+ }
+ else if (!strcmp(syntax, "TXML"))
+ {
+ strcpy(type, "txml");
+ return 0;
+ }
+ else if (!strcmp(syntax, "USmarc") || !strcmp(syntax, "MARC21"))
+ {
+ strcpy(type, "xml; charset=marc8-s");
+ return 0;
+ }
+ else return -1;
+ }
+ else return -1;
+ }
+}
+
+/**
+ * TODO Consider thread safety!!!
+ *
+ */
+int client_report_facets(struct client *cl, ZOOM_resultset rs) {
+ int facet_idx;
+ ZOOM_facet_field *facets = ZOOM_resultset_facets(rs);
+ int facet_num;
+ struct session *se = client_get_session(cl);
+ yaz_log(YLOG_DEBUG, "client_report_facets %p %p", rs, cl->resultset);
+
+ facet_num = ZOOM_resultset_facets_size(rs);
+ for (facet_idx = 0; facet_idx < facet_num; facet_idx++) {
+ const char *name = ZOOM_facet_field_name(facets[facet_idx]);
+ size_t term_idx;
+ size_t term_num = ZOOM_facet_field_term_count(facets[facet_idx]);
+ for (term_idx = 0; term_idx < term_num; term_idx++ ) {
+ int freq;
+ const char *term = ZOOM_facet_field_get_term(facets[facet_idx], term_idx, &freq);
+ if (term)
+ add_facet(se, name, term, freq);
+ }
+ }
+
+ return 0;