+static void client_set_facets_request(struct client *cl, ZOOM_connection link)
+{
+ struct session_database *sdb = client_get_database(cl);
+
+ WRBUF w = wrbuf_alloc();
+
+ struct setting *s;
+
+ for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
+ {
+ const char *p = strchr(s->name + 3, ':');
+ if (!p)
+ {
+ yaz_log(YLOG_WARN, "Malformed facetmap name: %s", s->name);
+ }
+ else if (s->value && s->value[0])
+ {
+ wrbuf_puts(w, "@attr 1=");
+ yaz_encode_pqf_term(w, s->value, strlen(s->value));
+ if (s->next)
+ wrbuf_puts(w, ",");
+ }
+ }
+ yaz_log(YLOG_LOG, "using facets str: %s", wrbuf_cstr(w));
+ ZOOM_connection_option_set(link, "facets",
+ wrbuf_len(w) ? wrbuf_cstr(w) : 0);
+ wrbuf_destroy(w);
+}
+
+int client_has_facet(struct client *cl, const char *name)
+{
+ struct session_database *sdb = client_get_database(cl);
+ struct setting *s;
+
+ for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
+ {
+ const char *p = strchr(s->name + 3, ':');
+ if (p && !strcmp(name, p + 1))
+ return 1;
+ }
+ return 0;
+}
+