X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fsession.c;h=60f381308ab7c978805f40df9947471601304148;hb=687d1431ba75a222ee963d3b9c54efa4ba4f1599;hp=cdd588c63920f9a615ed8e91c782f9630e8f1573;hpb=5957bba20fb93c8c6829296d6ccf32e52b2114e2;p=pazpar2-moved-to-github.git diff --git a/src/session.c b/src/session.c index cdd588c..60f3813 100644 --- a/src/session.c +++ b/src/session.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2011 Index Data + Copyright (C) 2006-2012 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -523,13 +523,14 @@ static void select_targets_callback(struct session *se, { cl = client_create(db->database->id); client_set_database(cl, db); - client_set_session(cl, se); l = xmalloc(sizeof(*l)); l->client = cl; 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)); l->client = cl; @@ -550,6 +551,11 @@ static void session_reset_active_clients(struct session *se, while (l) { struct client_list *l_next = l->next; + + client_lock(l->client); + client_set_session(l->client, 0); /* mark client inactive */ + client_unlock(l->client); + xfree(l); l = l_next; } @@ -642,11 +648,9 @@ void session_sort(struct session *se, const char *field, int increasing) for (l = se->clients_active; l; l = l->next) { struct client *cl = l->client; - struct timeval tval; - if (client_prep_connection(cl, se->service->z3950_operation_timeout, - se->service->z3950_session_timeout, - se->service->server->iochan_man, - &tval)) + if (client_get_state(cl) == Client_Connecting || + client_get_state(cl) == Client_Idle || + client_get_state(cl) == Client_Working) client_start_search(cl); } session_leave(se); @@ -731,27 +735,24 @@ enum pazpar2_error_code session_search(struct session *se, no_failed_query++; else if (parse_ret == -2) no_failed_limit++; - else if (parse_ret == 0) - { - session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl)); - no_working++; - 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); - } else { - session_log(se, YLOG_LOG, "client REUSE %s", client_get_id(cl)); - no_working++; - if (client_prep_connection(cl, se->service->z3950_operation_timeout, + int r = + client_prep_connection(cl, se->service->z3950_operation_timeout, se->service->z3950_session_timeout, se->service->server->iochan_man, - &tval)) + &tval); + if (parse_ret == 1 && r == 2) { + session_log(se, YLOG_LOG, "client REUSE %s", client_get_id(cl)); client_reingest(cl); } + else if (r) + { + session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl)); + client_start_search(cl); + } + no_working++; } } facet_limits_destroy(facet_limits); @@ -961,7 +962,8 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se, res[*count].name = *name ? name : "Unknown"; res[*count].hits = client_get_hits(cl); res[*count].records = client_get_num_records(cl); - res[*count].diagnostic = client_get_diagnostic(cl); + res[*count].diagnostic = + client_get_diagnostic(cl, &res[*count].addinfo); res[*count].state = client_get_state_str(cl); res[*count].connected = client_get_connection(cl) ? 1 : 0; session_settings_dump(se, client_get_database(cl), w); @@ -1057,26 +1059,31 @@ void perform_termlist(struct http_channel *c, struct session *se, char **names; int num_names = 0; - if (name) - nmem_strsplit(nmem_tmp, ",", name, &names, &num_names); + if (!name) + name = "*"; + + nmem_strsplit(nmem_tmp, ",", name, &names, &num_names); session_enter(se); for (j = 0; j < num_names; j++) { const char *tname; - - wrbuf_puts(c->wrbuf, "wrbuf, names[j]); - wrbuf_puts(c->wrbuf, "\">\n"); + int must_generate_empty = 1; /* bug 5350 */ for (i = 0; i < se->num_termlists; i++) { tname = se->termlists[i].name; - if (num_names > 0 && !strcmp(names[j], tname)) + if (!strcmp(names[j], tname) || !strcmp(names[j], "*")) { struct termlist_score **p = 0; int len; + + wrbuf_puts(c->wrbuf, "wrbuf, tname); + wrbuf_puts(c->wrbuf, "\">\n"); + must_generate_empty = 0; + p = termlist_highscore(se->termlists[i].termlist, &len); if (p) { @@ -1098,14 +1105,26 @@ void perform_termlist(struct http_channel *c, struct session *se, wrbuf_puts(c->wrbuf, "\n"); } } + wrbuf_puts(c->wrbuf, "\n"); } } tname = "xtargets"; - if (num_names > 0 && !strcmp(names[j], tname)) + if (!strcmp(names[j], tname) || !strcmp(names[j], "*")) { + wrbuf_puts(c->wrbuf, "wrbuf, tname); + wrbuf_puts(c->wrbuf, "\">\n"); + targets_termlist_nb(c->wrbuf, se, num, c->nmem); + wrbuf_puts(c->wrbuf, "\n"); + must_generate_empty = 0; + } + if (must_generate_empty) + { + wrbuf_puts(c->wrbuf, "wrbuf, names[j]); + wrbuf_puts(c->wrbuf, "\"/>\n"); } - wrbuf_puts(c->wrbuf, "\n"); } session_leave(se); nmem_destroy(nmem_tmp); @@ -1744,6 +1763,8 @@ static int ingest_to_cluster(struct client *cl, struct record_metadata *rec_md = 0; int md_field_id = -1; int sk_field_id = -1; + int rank = 0; + xmlChar *rank_str = 0; type = xmlGetProp(n, (xmlChar *) "type"); value = xmlNodeListGetString(xdoc, n->children, 1); @@ -1757,6 +1778,15 @@ static int ingest_to_cluster(struct client *cl, continue; ser_md = &service->metadata[md_field_id]; + + rank_str = xmlGetProp(n, (xmlChar *) "rank"); + if (rank_str) + { + rank = atoi((const char *) rank_str); + xmlFree(rank_str); + } + else + rank = ser_md->rank; if (ser_md->sortkey_offset >= 0) { @@ -1856,10 +1886,11 @@ static int ingest_to_cluster(struct client *cl, // ranking of _all_ fields enabled ... - if (ser_md->rank) + if (rank) + { relevance_countwords(se->relevance, cluster, - (char *) value, ser_md->rank, - ser_md->name); + (char *) value, rank, ser_md->name); + } // construct facets ... unless the client already has reported them if (ser_md->termlist && !client_has_facet(cl, (char *) type)) @@ -1911,7 +1942,7 @@ void session_log(struct session *s, int level, const char *fmt, ...) va_start(ap, fmt); yaz_vsnprintf(buf, sizeof(buf)-30, fmt, ap); - yaz_log(level, "Session (%u): %s", s->session_id, buf); + yaz_log(level, "Session %u: %s", s->session_id, buf); va_end(ap); }