{
const char *s;
- if (!sdb->settings)
- {
- session_log(se, YLOG_WARN, "No settings on %s", sdb->database->id);
- return -1;
- }
- if ((s = session_setting_oneval(sdb, PZ_XSLT)))
+ if (sdb->settings && sdb->settings[PZ_XSLT] && !sdb->map &&
+ (s = session_setting_oneval(sdb, PZ_XSLT)))
{
char auto_stylesheet[256];
}
}
sdb->map = normalize_cache_get(se->normalize_cache,
- se->service->server->config, s);
+ se->service, s);
if (!sdb->map)
return -1;
}
return 0;
}
-// This analyzes settings and recomputes any supporting data structures
-// if necessary.
-static int prepare_session_database(struct session *se,
- struct session_database *sdb)
-{
- if (!sdb->settings)
- {
- session_log(se, YLOG_WARN,
- "No settings associated with %s", sdb->database->id);
- return -1;
- }
- if (sdb->settings[PZ_XSLT] && !sdb->map)
- {
- if (prepare_map(se, sdb) < 0)
- return -1;
- }
- return 0;
-}
-
// called if watch should be removed because http_channel is to be destroyed
static void session_watch_cancel(void *data, struct http_channel *c,
void *data2)
static void select_targets_callback(struct session *se,
struct session_database *db)
{
- struct client *cl = client_create(db->database->id);
+ struct client *cl;
struct client_list *l;
- client_set_database(cl, db);
+ for (l = se->clients_cached; l; l = l->next)
+ if (client_get_database(l->client) == db)
+ break;
- client_set_session(cl, se);
+ if (l)
+ cl = l->client;
+ else
+ {
+ 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;
+ }
l = xmalloc(sizeof(*l));
l->client = cl;
- l->next = se->clients;
- se->clients = l;
+ l->next = se->clients_active;
+ se->clients_active = l;
}
-static void session_remove_clients(struct session *se)
+static void session_reset_active_clients(struct session *se,
+ struct client_list *new_list)
{
struct client_list *l;
session_enter(se);
- l = se->clients;
- se->clients = 0;
+ l = se->clients_active;
+ se->clients_active = new_list;
+ session_leave(se);
+
+ while (l)
+ {
+ struct client_list *l_next = l->next;
+ xfree(l);
+ l = l_next;
+ }
+}
+
+static void session_remove_cached_clients(struct session *se)
+{
+ struct client_list *l;
+
+ session_reset_active_clients(se, 0);
+
+ session_enter(se);
+ l = se->clients_cached;
+ se->clients_cached = 0;
session_leave(se);
while (l)
struct client_list *l;
int res = 0;
- for (l = s->clients; l; l = l->next)
+ for (l = s->clients_active; l; l = l->next)
if (client_is_active(l->client))
res++;
struct client_list *l;
int res = 0;
- for (l = s->clients; l; l = l->next)
+ for (l = s->clients_active; l; l = l->next)
if (client_is_active_preferred(l->client))
res++;
session_log(s, YLOG_DEBUG, "Has %d active preferred clients.", res);
sr->next = se->sorted_results;
se->sorted_results = sr;
- for (l = se->clients; l; l = l->next)
+ for (l = se->clients_active; l; l = l->next)
{
struct client *cl = l->client;
const char *strategy_plus_sort = get_strategy_plus_sort(cl, field);
int live_channels = 0;
int no_working = 0;
int no_failed = 0;
- struct client_list *l;
+ struct client_list *l, *l0;
struct timeval tval;
facet_limits_t facet_limits;
*addinfo = 0;
- session_remove_clients(se);
+ if (se->settings_modified)
+ session_remove_cached_clients(se);
+ else
+ session_reset_active_clients(se, 0);
session_enter(se);
reclist_destroy(se->reclist);
se->reclist = 0;
+ se->settings_modified = 0;
relevance_destroy(&se->relevance);
nmem_reset(se->nmem);
se->total_records = se->total_merged = 0;
session_leave(se);
return PAZPAR2_MALFORMED_PARAMETER_VALUE;
}
- for (l = se->clients; l; l = l->next)
+
+ l0 = se->clients_active;
+ se->clients_active = 0;
+ session_leave(se);
+
+ for (l = l0; l; l = l->next)
{
+ int parse_ret;
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));
- if (startrecs)
- client_set_startrecs(cl, atoi(startrecs));
- if (prepare_session_database(se, client_get_database(cl)) < 0)
- ;
- else if (client_parse_query(cl, query, facet_limits) < 0)
+ if (prepare_map(se, client_get_database(cl)) < 0)
+ continue;
+
+ parse_ret = client_parse_query(cl, query, facet_limits, startrecs,
+ maxrecs);
+ if (parse_ret < 0)
no_failed++;
- else
+ 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,
&tval))
client_start_search(cl, strategy_plus_sort, increasing);
}
+ 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,
+ se->service->z3950_session_timeout,
+ se->service->server->iochan_man,
+ &tval))
+ {
+ client_reingest(cl);
+ }
+ }
}
facet_limits_destroy(facet_limits);
- session_leave(se);
+ session_reset_active_clients(se, l0);
+
if (no_working == 0)
{
if (no_failed > 0)
else
return PAZPAR2_NO_TARGETS;
}
+ yaz_log(YLOG_LOG, "session_start_search done");
return PAZPAR2_NO_ERROR;
}
new->next = sdb->settings[offset];
sdb->settings[offset] = new;
+ se->settings_modified = 1;
+
// Force later recompute of settings-driven data structures
// (happens when a search starts and client connections are prepared)
switch (offset)
}
}
-void session_destroy(struct session *se) {
+void session_destroy(struct session *se)
+{
struct session_database *sdb;
session_log(se, YLOG_DEBUG, "Destroying");
session_use(-1);
- session_remove_clients(se);
+ session_remove_cached_clients(se);
for (sdb = se->databases; sdb; sdb = sdb->next)
session_database_destroy(sdb);
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)
session->number_of_warnings_unknown_metadata = 0;
session->num_termlists = 0;
session->reclist = 0;
- session->clients = 0;
+ session->clients_active = 0;
+ session->clients_cached = 0;
+ session->settings_modified = 0;
session->session_nmem = nmem;
session->nmem = nmem_create();
session->databases = 0;
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)
{
struct client_list *l;
size_t sz = 0;
- for (l = se->clients; l; l = l->next)
+ for (l = se->clients_active; l; l = l->next)
sz++;
res = nmem_malloc(nmem, sizeof(*res) * sz);
*count = 0;
- for (l = se->clients; l; l = l->next)
+ for (l = se->clients_active; l; l = l->next)
{
struct client *cl = l->client;
WRBUF w = wrbuf_alloc();
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)++;
}
for (j = 0; j < num_names; j++)
{
const char *tname;
+
+ wrbuf_puts(c->wrbuf, "<list name=\"");
+ wrbuf_xmlputs(c->wrbuf, names[j]);
+ wrbuf_puts(c->wrbuf, "\">\n");
+
for (i = 0; i < se->num_termlists; i++)
{
tname = se->termlists[i].name;
if (p)
{
int i;
- wrbuf_puts(c->wrbuf, "<list name=\"");
- wrbuf_xmlputs(c->wrbuf, tname);
- wrbuf_puts(c->wrbuf, "\">\n");
for (i = 0; i < len && i < num; i++)
{
// prevent sending empty term elements
p[i]->frequency);
wrbuf_puts(c->wrbuf, "</term>\n");
}
- wrbuf_puts(c->wrbuf, "</list>\n");
}
}
}
tname = "xtargets";
if (num_names > 0 && !strcmp(names[j], tname))
{
- wrbuf_puts(c->wrbuf, "<list name=\"");
- wrbuf_xmlputs(c->wrbuf, tname);
- wrbuf_puts(c->wrbuf, "\">\n");
targets_termlist_nb(c->wrbuf, se, num, c->nmem);
- wrbuf_puts(c->wrbuf, "</list>\n");
}
+ wrbuf_puts(c->wrbuf, "</list>\n");
}
session_leave(se);
nmem_destroy(nmem_tmp);
*total = reclist_get_num_records(se->reclist);
*sumhits = 0;
- for (l = se->clients; l; l = l->next)
+ for (l = se->clients_active; l; l = l->next)
*sumhits += client_get_hits(l->client);
for (i = 0; i < start; i++)
memset(stat, 0, sizeof(*stat));
stat->num_hits = 0;
- for (l = se->clients; l; l = l->next)
+ for (l = se->clients_active; l; l = l->next)
{
struct client *cl = l->client;
if (!client_get_connection(cl))
/* 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);
// 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: