+int client_parse_sort(struct client *cl, struct reclist_sortparms *sp)
+{
+ struct session *se = client_get_session(cl);
+ if (sp)
+ { /* first entry is current sorting ! */
+ const char *sort_strategy_and_spec =
+ get_strategy_plus_sort(cl, se->sorted_results->name);
+
+ int increasing = se->sorted_results->increasing;
+ // int type = se->sorted_results->type;
+ if (sort_strategy_and_spec && strlen(sort_strategy_and_spec) < 40)
+ {
+ char strategy[50], *p;
+ strcpy(strategy, sort_strategy_and_spec);
+ p = strchr(strategy, ':');
+ if (p)
+ {
+ // Split the string in two
+ *p++ = 0;
+ while (*p == ' ')
+ p++;
+ if (increasing)
+ strcat(p, " <");
+ else
+ strcat(p, " >");
+ yaz_log(YLOG_LOG, "Client %s: applying sorting %s %s", client_get_id(cl), strategy, p);
+ if (!cl->sort_strategy || strcmp(cl->sort_strategy, strategy))
+ cl->same_search = 0;
+ if (!cl->sort_criteria || strcmp(cl->sort_criteria, p))
+ cl->same_search = 0;
+ if (cl->same_search == 0) {
+ cl->sort_strategy = nmem_strdup(se->nmem, strategy);
+ cl->sort_criteria = nmem_strdup(se->nmem, p);
+ }
+ }
+ else {
+ yaz_log(YLOG_LOG, "Client %s: Invalid sort strategy and spec found %s", client_get_id(cl), sort_strategy_and_spec);
+ cl->sort_strategy = 0;
+ cl->sort_criteria = 0;
+ }
+ } else {
+ yaz_log(YLOG_LOG, "Client %s: No sort strategy and spec found.", client_get_id(cl));
+ cl->sort_strategy = 0;
+ cl->sort_criteria = 0;
+ }
+
+ }
+ return cl->same_search;
+}
+