no_session_total += delta;
sessions = no_sessions;
yaz_mutex_leave(g_session_mutex);
- yaz_log(YLOG_DEBUG, "%s sesions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), no_sessions);
+ yaz_log(YLOG_DEBUG, "%s sessions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), no_sessions);
return sessions;
}
-int sessions_count(void) {
+int sessions_count(void)
+{
return session_use(0);
}
-int session_count_total(void) {
+int session_count_total(void)
+{
int total = 0;
if (!g_session_mutex)
return 0;
return total;
}
-
static void log_xml_doc(xmlDoc *doc)
{
FILE *lf = yaz_log_file();
yaz_mutex_leave(s->session_mutex);
}
-// Recursively traverse query structure to extract terms.
-void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num)
-{
- char **words;
- int numwords;
- int i;
-
- switch (n->kind)
- {
- case CCL_RPN_AND:
- case CCL_RPN_OR:
- case CCL_RPN_NOT:
- case CCL_RPN_PROX:
- pull_terms(nmem, n->u.p[0], termlist, num);
- pull_terms(nmem, n->u.p[1], termlist, num);
- break;
- case CCL_RPN_TERM:
- nmem_strsplit(nmem, " ", n->u.t.term, &words, &numwords);
- for (i = 0; i < numwords; i++)
- termlist[(*num)++] = words[i];
- break;
- default: // NOOP
- break;
- }
-}
-
-
void add_facet(struct session *s, const char *type, const char *value, int count)
{
struct conf_service *service = s->service;
for (i = 0; i < service->num_metadata; i++)
if (!strcmp((service->metadata + i)->name, type))
icu_chain_id = (service->metadata + i)->facetrule;
- yaz_log(YLOG_LOG, "icu_chain id=%s", icu_chain_id ? icu_chain_id : "null");
-
if (!icu_chain_id)
icu_chain_id = "facet";
prt = pp2_charset_token_create(service->charsets, icu_chain_id);
}
pp2_charset_token_destroy(prt);
- yaz_log(YLOG_LOG, "facet norm=%s", wrbuf_cstr(facet_wrbuf));
- yaz_log(YLOG_LOG, "facet display=%s", wrbuf_cstr(display_wrbuf));
if (wrbuf_len(facet_wrbuf))
{
int i;
}
//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_list *l;
client_set_database(cl, db);
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++;
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)
{
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, "<term>\n");
+
+ wrbuf_puts(wrbuf, "<id>");
+ wrbuf_xmlputs(wrbuf, ht[i].id);
+ wrbuf_puts(wrbuf, "</id>\n");
+
+ wrbuf_puts(wrbuf, "<name>");
+ if (!ht[i].name || !ht[i].name[0])
+ wrbuf_xmlputs(wrbuf, "NO TARGET NAME");
+ else
+ wrbuf_xmlputs(wrbuf, ht[i].name);
+ wrbuf_puts(wrbuf, "</name>\n");
+
+ wrbuf_printf(wrbuf, "<frequency>" ODR_INT_PRINTF "</frequency>\n",
+ ht[i].hits);
+
+ wrbuf_puts(wrbuf, "<state>");
+ wrbuf_xmlputs(wrbuf, ht[i].state);
+ wrbuf_puts(wrbuf, "</state>\n");
+
+ wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n",
+ ht[i].diagnostic);
+ wrbuf_puts(wrbuf, "</term>\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, "<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
+ if (!p[i]->display_term || !p[i]->display_term[0])
+ continue;
+
+ wrbuf_puts(c->wrbuf, "<term>");
+ wrbuf_puts(c->wrbuf, "<name>");
+ wrbuf_xmlputs(c->wrbuf, p[i]->display_term);
+ wrbuf_puts(c->wrbuf, "</name>");
+
+ wrbuf_printf(c->wrbuf,
+ "<frequency>%d</frequency>",
+ 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");
+ }
+ }
+ session_leave(se);
+ nmem_destroy(nmem_tmp);
+}
+
#ifdef MISSING_HEADERS
void report_nmem_stats(void)
{