X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fsession.c;h=21a47294f11bd0133a8d3598ac830b9406dca1b3;hb=f5a8d2cdf270eddfd7bb3be07e4fb4c38dbf807c;hp=c9628e45d37e294fd8928896af5b6c423800ad58;hpb=9d9593c47d0ab73b331d85c64e04b516ba9c6a7f;p=pazpar2-moved-to-github.git diff --git a/src/session.c b/src/session.c index c9628e4..21a4729 100644 --- a/src/session.c +++ b/src/session.c @@ -438,7 +438,7 @@ static int prepare_map(struct session *se, struct session_database *sdb) } } sdb->map = normalize_cache_get(se->normalize_cache, - se->service->server->config, s); + se->service, s); if (!sdb->map) return -1; } @@ -597,7 +597,32 @@ int session_is_preferred_clients_ready(struct session *s) return res == 0; } -void search_sort(struct session *se, const char *field, 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 session_sort(struct session *se, const char *field, int increasing) { struct session_sorted_results *sr; struct client_list *l; @@ -628,26 +653,7 @@ void search_sort(struct session *se, const char *field, int increasing) 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; - } - } - + const char *strategy_plus_sort = get_strategy_plus_sort(cl, field); if (strategy_plus_sort) { struct timeval tval; @@ -655,30 +661,20 @@ void search_sort(struct session *se, const char *field, int increasing) 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); - } - } + client_start_search(cl, strategy_plus_sort, increasing); } } session_leave(se); } -enum pazpar2_error_code search(struct session *se, - const char *query, - const char *startrecs, const char *maxrecs, - const char *filter, - const char *limit, - const char **addinfo) +enum pazpar2_error_code session_search(struct session *se, + const char *query, + const char *startrecs, + const char *maxrecs, + const char *filter, + const char *limit, + const char **addinfo, + const char *sort_field, int increasing) { int live_channels = 0; int no_working = 0; @@ -703,8 +699,8 @@ enum pazpar2_error_code search(struct session *se, /* reset list of sorted results and clear to relevance search */ se->sorted_results = nmem_malloc(se->nmem, sizeof(*se->sorted_results)); - se->sorted_results->field = nmem_strdup(se->nmem, "relevance"); - se->sorted_results->increasing = 0; + se->sorted_results->field = nmem_strdup(se->nmem, sort_field); + se->sorted_results->increasing = increasing; se->sorted_results->next = 0; live_channels = select_targets(se, filter); @@ -729,6 +725,7 @@ enum pazpar2_error_code 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)); @@ -745,7 +742,7 @@ enum pazpar2_error_code search(struct session *se, se->service->z3950_session_timeout, se->service->server->iochan_man, &tval)) - client_start_search(cl, 0, 0); + client_start_search(cl, strategy_plus_sort, increasing); } } facet_limits_destroy(facet_limits); @@ -872,12 +869,6 @@ void session_destroy(struct session *se) { yaz_mutex_destroy(&se->session_mutex); } -/* Depreciated: use session_destroy */ -void destroy_session(struct session *se) -{ - session_destroy(se); -} - size_t session_get_memory_status(struct session *session) { size_t session_nmem; if (session == 0) @@ -924,6 +915,8 @@ struct session *new_session(NMEM nmem, struct conf_service *service, return session; } +const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf); + static struct hitsbytarget *hitsbytarget_nb(struct session *se, int *count, NMEM nmem) { @@ -952,6 +945,9 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se, res[*count].connected = client_get_connection(cl) ? 1 : 0; session_settings_dump(se, client_get_database(cl), w); res[*count].settings_xml = nmem_strdup(nmem, wrbuf_cstr(w)); + wrbuf_rewind(w); + wrbuf_puts(w, ""); + res[*count].suggestions_xml = nmem_strdup(nmem, client_get_suggestions_xml(cl, w)); wrbuf_destroy(w); (*count)++; } @@ -1048,6 +1044,11 @@ void perform_termlist(struct http_channel *c, struct session *se, for (j = 0; j < num_names; j++) { const char *tname; + + wrbuf_puts(c->wrbuf, "wrbuf, names[j]); + wrbuf_puts(c->wrbuf, "\">\n"); + for (i = 0; i < se->num_termlists; i++) { tname = se->termlists[i].name; @@ -1059,9 +1060,6 @@ void perform_termlist(struct http_channel *c, struct session *se, 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 @@ -1078,19 +1076,15 @@ void perform_termlist(struct http_channel *c, struct session *se, 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"); } + wrbuf_puts(c->wrbuf, "\n"); } session_leave(se); nmem_destroy(nmem_tmp); @@ -1398,9 +1392,14 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, /* generate unique key if none is not generated already or is empty */ if (wrbuf_len(norm_wr) == 0) { - wrbuf_printf(norm_wr, "%s-%d", + wrbuf_printf(norm_wr, "position: %s-%d", client_get_id(cl), record_no); } + else + { + const char *lead = "content: "; + wrbuf_insert(norm_wr, 0, lead, strlen(lead)); + } if (wrbuf_len(norm_wr) > 0) mergekey_norm = nmem_strdup(nmem, wrbuf_cstr(norm_wr)); wrbuf_destroy(norm_wr); @@ -1535,6 +1534,9 @@ static int ingest_to_cluster(struct client *cl, xmlChar *value = 0; struct session *se = client_get_session(cl); struct conf_service *service = se->service; + int term_factor = 1; + struct record_cluster *cluster; + struct session_database *sdb = client_get_database(cl); struct record *record = record_create(se->nmem, service->num_metadata, service->num_sortkeys, cl, @@ -1594,25 +1596,22 @@ static int ingest_to_cluster(struct client *cl, } } - struct record_cluster *cluster = reclist_insert(se->reclist, - service, - record, - mergekey_norm, - &se->total_merged); + cluster = reclist_insert(se->reclist, service, record, + mergekey_norm, &se->total_merged); if (!cluster) return -1; - struct session_database *sdb = client_get_database(cl); - int term_factor = 1; - const char *use_term_factor_str = - session_setting_oneval(sdb, PZ_TERMLIST_TERM_FACTOR); - if (use_term_factor_str && use_term_factor_str[0] == '1') { - int maxrecs = client_get_maxrecs(cl); - int hits = (int) client_get_hits(cl); - term_factor = MAX(hits, maxrecs) / MAX(1, maxrecs); - assert(term_factor >= 1); - yaz_log(YLOG_DEBUG, "Using term factor: %d (%d / %d)", term_factor, MAX(hits, maxrecs), MAX(1, maxrecs)); + const char *use_term_factor_str = + session_setting_oneval(sdb, PZ_TERMLIST_TERM_FACTOR); + if (use_term_factor_str && use_term_factor_str[0] == '1') + { + int maxrecs = client_get_maxrecs(cl); + int hits = (int) client_get_hits(cl); + term_factor = MAX(hits, maxrecs) / MAX(1, maxrecs); + assert(term_factor >= 1); + yaz_log(YLOG_DEBUG, "Using term factor: %d (%d / %d)", term_factor, MAX(hits, maxrecs), MAX(1, maxrecs)); + } } if (global_parameters.dump_records) @@ -1665,6 +1664,9 @@ static int ingest_to_cluster(struct client *cl, // merged metadata rec_md = record_metadata_init(se->nmem, (const char *) value, ser_md->type, 0); + if (!rec_md) + continue; + wheretoput = &cluster->metadata[md_field_id]; // and polulate with data: