X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Fsession.c;h=4478ececb411d7f5fafb8b2c1ed2006394986ac8;hb=d65081fd86127344075a112002adbfa32ff88f11;hp=fc021a87510c046ca378cc7968077213adce0324;hpb=4d9f530309235e8c78d50f82196f135c3127c064;p=pazpar2-moved-to-github.git
diff --git a/src/session.c b/src/session.c
index fc021a8..4478ece 100644
--- a/src/session.c
+++ b/src/session.c
@@ -111,15 +111,17 @@ static int session_use(int delta)
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;
@@ -129,7 +131,6 @@ int session_count_total(void) {
return total;
}
-
static void log_xml_doc(xmlDoc *doc)
{
FILE *lf = yaz_log_file();
@@ -158,33 +159,6 @@ static void session_leave(struct session *s)
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;
@@ -198,8 +172,6 @@ void add_facet(struct session *s, const char *type, const char *value, int count
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);
@@ -231,8 +203,6 @@ void add_facet(struct session *s, const char *type, const char *value, int count
}
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;
@@ -551,9 +521,9 @@ 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_list *l;
client_set_database(cl, db);
@@ -867,13 +837,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++;
@@ -898,10 +868,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)
{
@@ -919,6 +897,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)
{