+int yaz_solr_sortkeys_to_sort_spec(const char *solr_sortkeys, WRBUF w)
+{
+ /* Solr sortkey layout: field order[, field order] */
+ /* see cql_sortby_to_sortkeys of YAZ. */
+ char **sortspec;
+ int num_sortspec = 0;
+ int i;
+ NMEM nmem = nmem_create();
+
+ if (solr_sortkeys)
+ nmem_strsplit(nmem, ",", solr_sortkeys, &sortspec, &num_sortspec);
+ for (i = 0; i < num_sortspec; i++)
+ {
+ char **arg;
+ int num_arg;
+ char order = 'a';
+ int case_sensitive = 0;
+ nmem_strsplitx(nmem, " ", sortspec[i], &arg, &num_arg, 0);
+
+ if (num_arg != 2)
+ return -1;
+
+ if (!yaz_matchstr(arg[1], "asc"))
+ order = 'a';
+ else if (!yaz_matchstr(arg[1], "desc"))
+ order = 'd';
+ else
+ return -1;
+
+ if (i)
+ wrbuf_puts(w, " ");
+
+ wrbuf_puts(w, arg[0]); /* field */
+ wrbuf_puts(w, " ");
+
+ wrbuf_putc(w, order);
+ // Always in-sensitive
+ wrbuf_puts(w, case_sensitive ? "s" : "i");
+ }
+ nmem_destroy(nmem);
+ return 0;
+}
+
+