From: Adam Dickmeiss Date: Thu, 10 Nov 2011 10:04:33 +0000 (+0100) Subject: client_start_search only takes client argument again X-Git-Tag: mobile-beta-1~3^2 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=fb486d4fa4ebc56c76bbc8f25c819b1bb4a144f7;p=pazpar2-moved-to-github.git client_start_search only takes client argument again So that we re-issue it when host has been resolved. --- diff --git a/src/client.c b/src/client.c index 8751137..510cf68 100644 --- a/src/client.c +++ b/src/client.c @@ -683,12 +683,37 @@ int client_has_facet(struct client *cl, const char *name) return 0; } -void client_start_search(struct client *cl, const char *sort_strategy_and_spec, - int increasing) +static const char *get_strategy_plus_sort(struct client *l, const char *field) +{ + struct session_database *sdb = client_get_database(l); + struct setting *s; + + const char *strategy_plus_sort = 0; + + for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next) + { + char *p = strchr(s->name + 3, ':'); + if (!p) + { + yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name); + continue; + } + p++; + if (!strcmp(p, field)) + { + strategy_plus_sort = s->value; + break; + } + } + return strategy_plus_sort; +} + +void client_start_search(struct client *cl) { struct session_database *sdb = client_get_database(cl); struct connection *co = client_get_connection(cl); ZOOM_connection link = connection_get_link(co); + struct session *se = client_get_session(cl); ZOOM_resultset rs; const char *opt_piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK); const char *opt_queryenc = session_setting_oneval(sdb, PZ_QUERYENCODING); @@ -767,23 +792,39 @@ void client_start_search(struct client *cl, const char *sort_strategy_and_spec, ZOOM_query_prefix(q, cl->pquery); } - if (sort_strategy_and_spec && - strlen(sort_strategy_and_spec) < 40 /* spec below */) - { - char spec[50], *p; - strcpy(spec, sort_strategy_and_spec); - p = strchr(spec, ':'); - if (p) + if (se->sorted_results) + { /* first entry is current sorting ! */ + const char *sort_strategy_and_spec = + get_strategy_plus_sort(cl, se->sorted_results->field); + int increasing = se->sorted_results->increasing; + if (sort_strategy_and_spec && strlen(sort_strategy_and_spec) < 40) { - *p++ = '\0'; /* cut the string in two */ - while (*p == ' ') - p++; - if (increasing) - strcat(p, " <"); - else - strcat(p, " >"); - yaz_log(YLOG_LOG, "applying %s %s", spec, p); - ZOOM_query_sortby2(q, spec, p); + char spec[50], *p; + strcpy(spec, sort_strategy_and_spec); + p = strchr(spec, ':'); + if (p) + { + *p++ = '\0'; /* cut the string in two */ + while (*p == ' ') + p++; + if (increasing) + strcat(p, " <"); + else + strcat(p, " >"); + yaz_log(YLOG_LOG, "applying %s %s", spec, p); + ZOOM_query_sortby2(q, spec, p); + } + } + else + { + /* no native sorting.. If this is not the first search, then + skip it entirely */ + if (se->sorted_results->next) + { + ZOOM_query_destroy(q); + client_set_state_nb(cl, Client_Idle); + return; + } } } rs = ZOOM_connection_search(link, q); diff --git a/src/client.h b/src/client.h index 9cc9666..29eeb7e 100644 --- a/src/client.h +++ b/src/client.h @@ -77,8 +77,7 @@ int client_prep_connection(struct client *cl, int operation_timeout, int session_timeout, iochan_man_t iochan, const struct timeval *abstime); -void client_start_search(struct client *cl, const char *sort_strategy_and_spec, - int increasing); +void client_start_search(struct client *cl); void client_set_session(struct client *cl, struct session *se); int client_is_active(struct client *cl); int client_is_active_preferred(struct client *cl); diff --git a/src/connection.c b/src/connection.c index a3b0c65..1c7d467 100644 --- a/src/connection.c +++ b/src/connection.c @@ -399,7 +399,7 @@ start: { yaz_mutex_leave(host->mutex); connection_connect(con, iochan_man); - client_start_search(con->client, 0, 0); /* TODO */ + client_start_search(con->client); goto start; } } diff --git a/src/session.c b/src/session.c index 21a4729..f2d7e2d 100644 --- a/src/session.c +++ b/src/session.c @@ -95,12 +95,6 @@ struct client_list { struct client_list *next; }; -struct session_sorted_results { - const char *field; - int increasing; - struct session_sorted_results *next; -}; - /* session counting (1) , disable client counting (0) */ static YAZ_MUTEX g_session_mutex = 0; static int no_sessions = 0; @@ -597,31 +591,6 @@ int session_is_preferred_clients_ready(struct session *s) return res == 0; } -static const char *get_strategy_plus_sort(struct client *l, const char *field) -{ - struct session_database *sdb = client_get_database(l); - struct setting *s; - - const char *strategy_plus_sort = 0; - - for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next) - { - char *p = strchr(s->name + 3, ':'); - if (!p) - { - yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name); - continue; - } - p++; - if (!strcmp(p, field)) - { - strategy_plus_sort = s->value; - break; - } - } - return strategy_plus_sort; -} - void session_sort(struct session *se, const char *field, int increasing) { struct session_sorted_results *sr; @@ -653,16 +622,12 @@ void session_sort(struct session *se, const char *field, int increasing) for (l = se->clients; l; l = l->next) { struct client *cl = l->client; - const char *strategy_plus_sort = get_strategy_plus_sort(cl, field); - if (strategy_plus_sort) - { - struct timeval tval; - if (client_prep_connection(cl, se->service->z3950_operation_timeout, - se->service->z3950_session_timeout, - se->service->server->iochan_man, - &tval)) - client_start_search(cl, strategy_plus_sort, increasing); - } + struct timeval tval; + if (client_prep_connection(cl, se->service->z3950_operation_timeout, + se->service->z3950_session_timeout, + se->service->server->iochan_man, + &tval)) + client_start_search(cl); } session_leave(se); } @@ -725,7 +690,6 @@ enum pazpar2_error_code session_search(struct session *se, for (l = se->clients; l; l = l->next) { struct client *cl = l->client; - const char *strategy_plus_sort = get_strategy_plus_sort(cl, sort_field); if (maxrecs) client_set_maxrecs(cl, atoi(maxrecs)); @@ -742,7 +706,7 @@ enum pazpar2_error_code session_search(struct session *se, se->service->z3950_session_timeout, se->service->server->iochan_man, &tval)) - client_start_search(cl, strategy_plus_sort, increasing); + client_start_search(cl); } } facet_limits_destroy(facet_limits); diff --git a/src/session.h b/src/session.h index 54ccd6c..98057d6 100644 --- a/src/session.h +++ b/src/session.h @@ -191,6 +191,12 @@ void session_log(struct session *s, int level, const char *fmt, ...) ; #endif +struct session_sorted_results { + const char *field; + int increasing; + struct session_sorted_results *next; +}; + /* * Local variables: * c-basic-offset: 4