X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fsession.c;h=684cd8e0b52086a889aca92bd543de9950de8c41;hb=646158a86d80e5ef0221ef7d7ce2cfc6ba31eacc;hp=72feef6d0fb1d85cd42f92797c57583fc93f1253;hpb=f8d8d8ddec7c889411a09248f02e565de1d94cbc;p=pazpar2-moved-to-github.git diff --git a/src/session.c b/src/session.c index 72feef6..684cd8e 100644 --- a/src/session.c +++ b/src/session.c @@ -246,13 +246,13 @@ static xmlDoc *record_to_xml(struct session *se, if (!rdoc) { session_log(se, YLOG_FATAL, "Non-wellformed XML received from %s", - db->url); + db->id); return 0; } if (global_parameters.dump_records) { - session_log(se, YLOG_LOG, "Un-normalized record from %s", db->url); + session_log(se, YLOG_LOG, "Un-normalized record from %s", db->id); log_xml_doc(rdoc); } @@ -340,7 +340,7 @@ static xmlDoc *normalize_record(struct session *se, if (normalize_record_transform(sdb->map, &rdoc, (const char **)parms)) { session_log(se, YLOG_WARN, "Normalize failed from %s", - sdb->database->url); + sdb->database->id); } else { @@ -349,7 +349,7 @@ static xmlDoc *normalize_record(struct session *se, if (global_parameters.dump_records) { session_log(se, YLOG_LOG, "Normalized record from %s", - sdb->database->url); + sdb->database->id); log_xml_doc(rdoc); } } @@ -401,7 +401,7 @@ static int prepare_map(struct session *se, struct session_database *sdb) if (!sdb->settings) { - session_log(se, YLOG_WARN, "No settings on %s", sdb->database->url); + session_log(se, YLOG_WARN, "No settings on %s", sdb->database->id); return -1; } if ((s = session_setting_oneval(sdb, PZ_XSLT))) @@ -447,7 +447,7 @@ static int prepare_session_database(struct session *se, if (!sdb->settings) { session_log(se, YLOG_WARN, - "No settings associated with %s", sdb->database->url); + "No settings associated with %s", sdb->database->id); return -1; } if (sdb->settings[PZ_XSLT] && !sdb->map) @@ -521,11 +521,12 @@ void session_alert_watch(struct session *s, int what) } //callback for grep_databases -static void select_targets_callback(void *context, struct session_database *db) +static void select_targets_callback(struct session *se, + struct session_database *db) { - struct session *se = (struct session*) context; - struct client *cl = client_create(); + struct client *cl = client_create(db->database->id); struct client_list *l; + client_set_database(cl, db); client_set_session(cl, se); @@ -590,6 +591,59 @@ int session_is_preferred_clients_ready(struct session *s) return res == 0; } +void search_sort(struct session *se, const char *field, int increasing) +{ + struct client_list *l; + struct timeval tval; + + session_enter(se); + for (l = se->clients; l; l = l->next) + { + struct client *cl = l->client; + struct session_database *sdb = client_get_database(cl); + 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; + } + } + + if (strategy_plus_sort) + { + if (client_prep_connection(cl, se->service->z3950_operation_timeout, + se->service->z3950_session_timeout, + se->service->server->iochan_man, + &tval)) + { + char **array; + int num; + nmem_strsplit(se->nmem, ":", strategy_plus_sort, &array, &num); + + if (num == 2) + { + const char *sort_spec = array[1]; + while (*sort_spec == ' ') + sort_spec++; + client_start_search(cl, array[0], sort_spec); + } + } + } + } + session_leave(se); +} + enum pazpar2_error_code search(struct session *se, const char *query, const char *startrecs, const char *maxrecs, @@ -655,7 +709,7 @@ enum pazpar2_error_code search(struct session *se, se->service->z3950_session_timeout, se->service->server->iochan_man, &tval)) - client_start_search(cl); + client_start_search(cl, 0, 0); } } facet_limits_destroy(facet_limits); @@ -717,8 +771,6 @@ static struct session_database *load_session_database(struct session *se, { struct database *db = new_database(id, se->session_nmem); - resolve_database(se->service, db); - session_init_databases_fun((void*) se, db); // New sdb is head of se->databases list @@ -732,7 +784,7 @@ static struct session_database *find_session_database(struct session *se, struct session_database *sdb; for (sdb = se->databases; sdb; sdb = sdb->next) - if (!strcmp(sdb->database->url, id)) + if (!strcmp(sdb->database->id, id)) return sdb; return load_session_database(se, id); } @@ -837,13 +889,13 @@ struct session *new_session(NMEM nmem, struct conf_service *service, return session; } -struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) +static struct hitsbytarget *hitsbytarget_nb(struct session *se, + int *count, NMEM nmem) { struct hitsbytarget *res = 0; struct client_list *l; size_t sz = 0; - session_enter(se); for (l = se->clients; l; l = l->next) sz++; @@ -856,7 +908,7 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) const char *name = session_setting_oneval(client_get_database(cl), PZ_NAME); - res[*count].id = client_get_database(cl)->database->url; + res[*count].id = client_get_id(cl); res[*count].name = *name ? name : "Unknown"; res[*count].hits = client_get_hits(cl); res[*count].records = client_get_num_records(cl); @@ -868,10 +920,18 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) wrbuf_destroy(w); (*count)++; } - session_leave(se); return res; } +struct hitsbytarget *get_hitsbytarget(struct session *se, int *count, NMEM nmem) +{ + struct hitsbytarget *p; + session_enter(se); + p = hitsbytarget_nb(se, count, nmem); + session_leave(se); + return p; +} + struct termlist_score **get_termlist_score(struct session *se, const char *name, int *num) { @@ -889,6 +949,118 @@ struct termlist_score **get_termlist_score(struct session *se, return tl; } +// Compares two hitsbytarget nodes by hitcount +static int cmp_ht(const void *p1, const void *p2) +{ + const struct hitsbytarget *h1 = p1; + const struct hitsbytarget *h2 = p2; + return h2->hits - h1->hits; +} + +static int targets_termlist_nb(WRBUF wrbuf, struct session *se, int num, + NMEM nmem) +{ + struct hitsbytarget *ht; + int count, i; + + ht = hitsbytarget_nb(se, &count, nmem); + qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht); + for (i = 0; i < count && i < num && ht[i].hits > 0; i++) + { + + // do only print terms which have display names + + wrbuf_puts(wrbuf, "\n"); + + wrbuf_puts(wrbuf, ""); + wrbuf_xmlputs(wrbuf, ht[i].id); + wrbuf_puts(wrbuf, "\n"); + + wrbuf_puts(wrbuf, ""); + if (!ht[i].name || !ht[i].name[0]) + wrbuf_xmlputs(wrbuf, "NO TARGET NAME"); + else + wrbuf_xmlputs(wrbuf, ht[i].name); + wrbuf_puts(wrbuf, "\n"); + + wrbuf_printf(wrbuf, "" ODR_INT_PRINTF "\n", + ht[i].hits); + + wrbuf_puts(wrbuf, ""); + wrbuf_xmlputs(wrbuf, ht[i].state); + wrbuf_puts(wrbuf, "\n"); + + wrbuf_printf(wrbuf, "%d\n", + ht[i].diagnostic); + wrbuf_puts(wrbuf, "\n"); + } + return count; +} + +void perform_termlist(struct http_channel *c, struct session *se, + const char *name, int num) +{ + int i, j; + NMEM nmem_tmp = nmem_create(); + char **names; + int num_names = 0; + + if (name) + nmem_strsplit(nmem_tmp, ",", name, &names, &num_names); + + session_enter(se); + + for (j = 0; j < num_names; j++) + { + const char *tname; + for (i = 0; i < se->num_termlists; i++) + { + tname = se->termlists[i].name; + if (num_names > 0 && !strcmp(names[j], tname)) + { + struct termlist_score **p = 0; + int len; + p = termlist_highscore(se->termlists[i].termlist, &len); + if (p) + { + int i; + wrbuf_puts(c->wrbuf, "wrbuf, tname); + wrbuf_puts(c->wrbuf, "\">\n"); + for (i = 0; i < len && i < num; i++) + { + // prevent sending empty term elements + if (!p[i]->display_term || !p[i]->display_term[0]) + continue; + + wrbuf_puts(c->wrbuf, ""); + wrbuf_puts(c->wrbuf, ""); + wrbuf_xmlputs(c->wrbuf, p[i]->display_term); + wrbuf_puts(c->wrbuf, ""); + + wrbuf_printf(c->wrbuf, + "%d", + p[i]->frequency); + wrbuf_puts(c->wrbuf, "\n"); + } + wrbuf_puts(c->wrbuf, "\n"); + } + } + } + tname = "xtargets"; + if (num_names > 0 && !strcmp(names[j], tname)) + { + 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"); + } + } + session_leave(se); + nmem_destroy(nmem_tmp); +} + #ifdef MISSING_HEADERS void report_nmem_stats(void) { @@ -1186,7 +1358,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, if (wrbuf_len(norm_wr) == 0) { wrbuf_printf(norm_wr, "%s-%d", - client_get_database(cl)->database->url, record_no); + client_get_id(cl), record_no); } if (wrbuf_len(norm_wr) > 0) mergekey_norm = nmem_strdup(nmem, wrbuf_cstr(norm_wr)); @@ -1290,7 +1462,7 @@ int ingest_record(struct client *cl, const char *rec, if (!check_record_filter(root, sdb)) { session_log(se, YLOG_LOG, "Filtered out record no %d from %s", - record_no, sdb->database->url); + record_no, sdb->database->id); xmlFreeDoc(xdoc); return -2; } @@ -1350,7 +1522,7 @@ static int ingest_to_cluster(struct client *cl, return -1; if (global_parameters.dump_records) session_log(se, YLOG_LOG, "Cluster id %s from %s (#%d)", cluster->recid, - sdb->database->url, record_no); + sdb->database->id, record_no); relevance_newrec(se->relevance, cluster); // now parsing XML record and adding data to cluster or record metadata