{
char sort_string_buf[64], sort_flags[64];
Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
- odr_malloc (out, sizeof(*sksl));
+ odr_malloc(out, sizeof(*sksl));
int off;
sksl->num_specs = 0;
arg += off;
sksl->specs[sksl->num_specs++] = sks;
sks->sortElement = (Z_SortElement *)
- odr_malloc (out, sizeof(*sks->sortElement));
+ odr_malloc(out, sizeof(*sks->sortElement));
sks->sortElement->which = Z_SortElement_generic;
sks->sortElement->u.generic = sk;
while (i < 10 && sort_string && sort_string_sep)
{
Z_AttributeElement *el = (Z_AttributeElement *)
- odr_malloc (out, sizeof(*el));
+ odr_malloc(out, sizeof(*el));
sk->u.sortAttributes->list->attributes[i] = el;
el->attributeSet = 0;
el->attributeType = odr_intdup(out, atoi(sort_string));
return 0;
}
+int yaz_sort_spec_to_srw_sortkeys(Z_SortKeySpecList *sksl, WRBUF w)
+{
+ int i;
+ for (i = 0; i < sksl->num_specs; i++)
+ {
+ Z_SortKeySpec *sks = sksl->specs[i];
+ Z_SortKey *sk;
+
+ if (sks->sortElement->which != Z_SortElement_generic)
+ return -1;
+
+ sk = sks->sortElement->u.generic;
+
+ if (i)
+ wrbuf_puts(w, " ");
+
+ if (sk->which == Z_SortKey_sortAttributes)
+ return -1;
+ else if (sk->which == Z_SortKey_sortField)
+ {
+ wrbuf_puts(w, sk->u.sortField);
+ }
+ wrbuf_puts(w, ",,"); /* path is absent */
+ switch (*sks->sortRelation)
+ {
+ case Z_SortKeySpec_ascending:
+ wrbuf_puts(w, "1");
+ break;
+ case Z_SortKeySpec_descending:
+ wrbuf_puts(w, "0");
+ break;
+ }
+ wrbuf_puts(w, ",");
+ switch (*sks->caseSensitivity)
+ {
+ case Z_SortKeySpec_caseSensitive:
+ wrbuf_puts(w, "1");
+ break;
+ case Z_SortKeySpec_caseInsensitive:
+ wrbuf_puts(w, "0");
+ break;
+ }
+ wrbuf_puts(w, ",");
+ switch (sks->which)
+ {
+ case Z_SortKeySpec_null:
+ wrbuf_puts(w, "highValue");
+ break;
+ case Z_SortKeySpec_abort:
+ wrbuf_puts(w, "abort");
+ break;
+ case Z_SortKeySpec_missingValueData:
+ wrbuf_write(w, (const char *) sks->u.missingValueData->buf,
+ sks->u.missingValueData->len);
+ }
+ }
+ return 0;
+}
+
+int yaz_srw_sortkeys_to_sort_spec(const char *srw_sortkeys, WRBUF w)
+{
+ /* sru sortkey layout: path,schema,ascending,caseSensitive,missingValue */
+ /* see cql_sortby_to_sortkeys of YAZ. */
+ char **sortspec;
+ int num_sortspec = 0;
+ int i;
+ NMEM nmem = nmem_create();
+
+ if (srw_sortkeys)
+ nmem_strsplit_blank(nmem, srw_sortkeys, &sortspec, &num_sortspec);
+ if (num_sortspec > 0)
+ {
+ for (i = 0; i < num_sortspec; i++)
+ {
+ char **arg;
+ int num_arg;
+ int ascending = 1;
+ int case_sensitive = 0;
+ const char *missing = 0;
+ nmem_strsplitx(nmem, ",", sortspec[i], &arg, &num_arg, 0);
+
+ if (num_arg > 2 && arg[2][0])
+ ascending = atoi(arg[2]);
+ if (num_arg > 3 && arg[3][0])
+ case_sensitive = atoi(arg[3]);
+ if (num_arg > 4 && arg[4][0])
+ missing = arg[4];
+
+ if (i)
+ wrbuf_puts(w, " ");
+
+ wrbuf_puts(w, arg[0]); /* field */
+ wrbuf_puts(w, " ");
+
+ wrbuf_puts(w, ascending ? "a" : "d");
+ wrbuf_puts(w, case_sensitive ? "s" : "i");
+ if (missing)
+ {
+ if (!strcmp(missing, "omit"))
+ ;
+ else if (!strcmp(missing, "abort"))
+ wrbuf_puts(w, "!");
+ else if (!strcmp(missing, "lowValue"))
+ ;
+ else if (!strcmp(missing, "highValue"))
+ ;
+ else
+ {
+ wrbuf_puts(w, "=");
+ wrbuf_puts(w, missing);
+ }
+ }
+ }
+ }
+ nmem_destroy(nmem);
+ return 0;
+}
/*
* Local variables: