X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fsession.c;h=a294c8e4f07d19008138540390cd53111056da04;hb=cd5d11b2abd121a03a1075f7525112e7597cbc09;hp=1928aaef2929437a9b90d350c4c6251dfee6732c;hpb=3ca0687d9eab38a71b6cfefa4a522aa488a379ec;p=pazpar2-moved-to-github.git diff --git a/src/session.c b/src/session.c index 1928aae..a294c8e 100644 --- a/src/session.c +++ b/src/session.c @@ -228,18 +228,27 @@ static void session_add_id_facet(struct session *s, struct client *cl, } +// Look up a facet term, and return matching id +// If facet type not found, returns 0 +// If facet type found, but no matching term, returns "" const char *session_lookup_id_facet(struct session *s, struct client *cl, const char *type, const char *term) { + char *retval = 0; struct facet_id *t = s->facet_id_list; - for (; t; t = t->next) - if (!strcmp(client_get_id(cl), t->client_id) && - !strcmp(t->type, type) && !strcmp(t->term, term)) + for (; t; t = t->next) + { + if (!strcmp(client_get_id(cl), t->client_id) && !strcmp(t->type, type) ) { - return t->id; + retval = ""; + if ( !strcmp(t->term, term)) + { + return t->id; + } } - return 0; + } + return retval; } void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl) @@ -561,7 +570,6 @@ static void select_targets_callback(struct session *se, l->next = se->clients_cached; se->clients_cached = l; } - /* set session always. If may be 0 if client is not active */ client_set_session(cl, se); l = xmalloc(sizeof(*l)); @@ -610,6 +618,7 @@ static void session_remove_cached_clients(struct session *se) client_lock(l->client); client_set_session(l->client, 0); client_set_database(l->client, 0); + client_mark_dead(l->client); client_unlock(l->client); client_destroy(l->client); xfree(l); @@ -714,7 +723,7 @@ void session_sort(struct session *se, struct reclist_sortparms *sp, break; if (sr) { - session_log(se, YLOG_DEBUG, "session_sort: field=%s increasing=%d type=%d already fetched", + session_log(se, YLOG_LOG, "session_sort: field=%s increasing=%d type=%d already fetched", field, increasing, type); session_leave(se, "session_sort"); return; @@ -732,7 +741,7 @@ void session_sort(struct session *se, struct reclist_sortparms *sp, struct client *cl = l->client; // Assume no re-search is required. client_parse_init(cl, 1); - clients_research += client_parse_sort(cl, sp); + clients_research += client_parse_sort(cl, sp, 0); } if (!clients_research || se->clients_starting) { @@ -774,6 +783,7 @@ void session_sort(struct session *se, struct reclist_sortparms *sp, } session_enter(se, "session_sort"); se->clients_starting = 0; + se->force_position = 0; session_leave(se, "session_sort"); } } @@ -821,6 +831,7 @@ enum pazpar2_error_code session_search(struct session *se, int no_working = 0; int no_failed_query = 0; int no_failed_limit = 0; + int no_sortmap = 0; struct client_list *l; session_log(se, YLOG_DEBUG, "Search"); @@ -834,6 +845,7 @@ enum pazpar2_error_code session_search(struct session *se, return PAZPAR2_NO_ERROR; } se->clients_starting = 1; + se->force_position = 0; session_leave(se, "session_search0"); if (se->settings_modified) { @@ -874,6 +886,7 @@ enum pazpar2_error_code session_search(struct session *se, *addinfo = "limit"; session_leave(se, "session_search"); se->clients_starting = 0; + session_reset_active_clients(se, 0); return PAZPAR2_MALFORMED_PARAMETER_VALUE; } @@ -902,12 +915,19 @@ enum pazpar2_error_code session_search(struct session *se, else { client_parse_range(cl, startrecs, maxrecs); - client_parse_sort(cl, sp); + client_parse_sort(cl, sp, &no_sortmap); client_start_search(cl); no_working++; } } + yaz_log(YLOG_LOG, "session_search: no_working=%d no_sortmap=%d", + no_working, no_sortmap); session_enter(se, "session_search2"); + if (no_working == 1 && no_sortmap == 1) + { + se->force_position = 1; + yaz_log(YLOG_LOG, "force_position=1"); + } se->clients_starting = 0; session_leave(se, "session_search2"); if (no_working == 0) @@ -1028,8 +1048,11 @@ void session_apply_setting(struct session *se, const char *dbname, void session_destroy(struct session *se) { struct session_database *sdb; - session_log(se, YLOG_LOG, "destroy"); - session_use(-1); + int i = session_use(-1); + + session_log(se, YLOG_LOG, "destroy " + "session-total %d nmem-op %zd nmem-ses %zd", i, + nmem_total(se->nmem), nmem_total(se->session_nmem)); session_remove_cached_clients(se); for (sdb = se->databases; sdb; sdb = sdb->next) @@ -1039,10 +1062,6 @@ void session_destroy(struct session *se) reclist_destroy(se->reclist); xfree(se->mergekey); xfree(se->rank); - if (nmem_total(se->nmem)) - session_log(se, YLOG_DEBUG, "NMEN operation usage %zd", nmem_total(se->nmem)); - if (nmem_total(se->session_nmem)) - session_log(se, YLOG_DEBUG, "NMEN session usage %zd", nmem_total(se->session_nmem)); facet_limits_destroy(se->facet_limits); nmem_destroy(se->nmem); service_destroy(se->service); @@ -1091,6 +1110,7 @@ struct session *new_session(NMEM nmem, struct conf_service *service, session->mergekey = 0; session->rank = 0; session->clients_starting = 0; + session->force_position = 0; for (i = 0; i <= SESSION_WATCH_MAX; i++) { @@ -1100,9 +1120,9 @@ struct session *new_session(NMEM nmem, struct conf_service *service, session->normalize_cache = normalize_cache_create(); session->session_mutex = 0; pazpar2_mutex_create(&session->session_mutex, tmp_str); - session_log(session, YLOG_LOG, "create"); - session_use(1); + i = session_use(1); + session_log(session, YLOG_LOG, "create session-total %d", i); return session; } @@ -1409,6 +1429,7 @@ struct record_cluster **show_range_start(struct session *se, struct reclist_sortparms *spp; struct client_list *l; int i; + NMEM nmem_tmp = 0; #if USE_TIMING yaz_timing_t t = yaz_timing_create(); #endif @@ -1430,7 +1451,15 @@ struct record_cluster **show_range_start(struct session *se, *approx_hits += client_get_approximation(l->client); } } + if (se->force_position) + { + nmem_tmp = nmem_create(); + sp = reclist_parse_sortparms(nmem_tmp, "position:1", 0); + assert(sp); + } reclist_sort(se->reclist, sp); + if (nmem_tmp) + nmem_destroy(nmem_tmp); reclist_enter(se->reclist); *total = reclist_get_num_records(se->reclist);