+static int nativesyntax_to_type(struct session_database *sdb, char *type,
+ ZOOM_record rec)
+{
+ const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
+
+ if (s && *s)
+ {
+ if (!strncmp(s, "iso2709", 7))
+ {
+ const char *cp = strchr(s, ';');
+ yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s");
+ }
+ else if (!strncmp(s, "xml", 3))
+ {
+ strcpy(type, "xml");
+ }
+ else if (!strncmp(s, "txml", 4))
+ {
+ const char *cp = strchr(s, ';');
+ yaz_snprintf(type, 80, "txml; charset=%s", cp ? cp+1 : "marc-8s");
+ }
+ else
+ return -1;
+ return 0;
+ }
+ 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);
+ facet_num = ZOOM_resultset_facets_size(rs);
+ yaz_log(YLOG_DEBUG, "client_report_facets: %d", facet_num);
+
+ 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;
+}
+