X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Fsession.c;h=21a47294f11bd0133a8d3598ac830b9406dca1b3;hb=873be84689528ca10a1ded3dd4bbda24b6916882;hp=9b69b3860124c7ed292c48188c48c52c55ec7e01;hpb=98dbaf0f7a4ea46aa3330d79c90f802fc0671f41;p=pazpar2-moved-to-github.git
diff --git a/src/session.c b/src/session.c
index 9b69b38..21a4729 100644
--- a/src/session.c
+++ b/src/session.c
@@ -95,6 +95,12 @@ struct client_list {
struct client_list *next;
};
+struct session_sorted_results {
+ const char *field;
+ int increasing;
+ struct session_sorted_results *next;
+};
+
/* session counting (1) , disable client counting (0) */
static YAZ_MUTEX g_session_mutex = 0;
static int no_sessions = 0;
@@ -111,15 +117,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 +137,6 @@ int session_count_total(void) {
return total;
}
-
static void log_xml_doc(xmlDoc *doc)
{
FILE *lf = yaz_log_file();
@@ -158,37 +165,10 @@ 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;
- pp2_relevance_token_t prt;
+ pp2_charset_token_t prt;
const char *facet_component;
WRBUF facet_wrbuf = wrbuf_alloc();
WRBUF display_wrbuf = wrbuf_alloc();
@@ -197,13 +177,20 @@ 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)->icu_chain;
- yaz_log(YLOG_LOG, "icu_chain id=%s", icu_chain_id ? icu_chain_id : "null");
-
- prt = pp2_relevance_tokenize(service->facet_pct);
-
- pp2_relevance_first(prt, value, 0);
- while ((facet_component = pp2_relevance_token_next(prt)))
+ icu_chain_id = (service->metadata + i)->facetrule;
+ if (!icu_chain_id)
+ icu_chain_id = "facet";
+ prt = pp2_charset_token_create(service->charsets, icu_chain_id);
+ if (!prt)
+ {
+ yaz_log(YLOG_FATAL, "Unknown ICU chain '%s' for facet of type '%s'",
+ icu_chain_id, type);
+ wrbuf_destroy(facet_wrbuf);
+ wrbuf_destroy(display_wrbuf);
+ return;
+ }
+ pp2_charset_token_first(prt, value, 0);
+ while ((facet_component = pp2_charset_token_next(prt)))
{
const char *display_component;
if (*facet_component)
@@ -220,10 +207,8 @@ void add_facet(struct session *s, const char *type, const char *value, int count
wrbuf_puts(display_wrbuf, display_component);
}
}
- pp2_relevance_token_destroy(prt);
+ 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;
@@ -236,6 +221,7 @@ void add_facet(struct session *s, const char *type, const char *value, int count
{
session_log(s, YLOG_FATAL, "Too many termlists");
wrbuf_destroy(facet_wrbuf);
+ wrbuf_destroy(display_wrbuf);
return;
}
@@ -266,13 +252,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);
}
@@ -360,7 +346,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
{
@@ -369,7 +355,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);
}
}
@@ -421,7 +407,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)))
@@ -452,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;
}
@@ -467,7 +453,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)
@@ -541,11 +527,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);
@@ -610,12 +597,84 @@ int session_is_preferred_clients_ready(struct session *s)
return res == 0;
}
-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)
+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;
+
+ session_enter(se);
+
+ /* see if we already have sorted for this critieria */
+ for (sr = se->sorted_results; sr; sr = sr->next)
+ {
+ if (!strcmp(field, sr->field) && increasing == sr->increasing)
+ break;
+ }
+ if (sr)
+ {
+ yaz_log(YLOG_LOG, "search_sort: field=%s increasing=%d already fetched",
+ field, increasing);
+ session_leave(se);
+ return;
+ }
+ yaz_log(YLOG_LOG, "search_sort: field=%s increasing=%d must fetch",
+ field, increasing);
+ sr = nmem_malloc(se->nmem, sizeof(*sr));
+ sr->field = nmem_strdup(se->nmem, field);
+ sr->increasing = increasing;
+ sr->next = se->sorted_results;
+ se->sorted_results = sr;
+
+ for (l = se->clients; l; l = l->next)
+ {
+ struct client *cl = l->client;
+ const char *strategy_plus_sort = get_strategy_plus_sort(cl, field);
+ if (strategy_plus_sort)
+ {
+ struct timeval tval;
+ if (client_prep_connection(cl, se->service->z3950_operation_timeout,
+ se->service->z3950_session_timeout,
+ se->service->server->iochan_man,
+ &tval))
+ client_start_search(cl, strategy_plus_sort, increasing);
+ }
+ }
+ session_leave(se);
+}
+
+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;
@@ -635,8 +694,15 @@ enum pazpar2_error_code search(struct session *se,
se->reclist = 0;
relevance_destroy(&se->relevance);
nmem_reset(se->nmem);
- se->total_records = se->total_hits = se->total_merged = 0;
+ se->total_records = se->total_merged = 0;
se->num_termlists = 0;
+
+ /* 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, sort_field);
+ se->sorted_results->increasing = increasing;
+ se->sorted_results->next = 0;
+
live_channels = select_targets(se, filter);
if (!live_channels)
{
@@ -659,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));
@@ -675,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);
+ client_start_search(cl, strategy_plus_sort, increasing);
}
}
facet_limits_destroy(facet_limits);
@@ -737,8 +804,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
@@ -752,7 +817,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);
}
@@ -804,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)
@@ -835,7 +894,6 @@ struct session *new_session(NMEM nmem, struct conf_service *service,
session_log(session, YLOG_DEBUG, "New");
session->service = service;
session->relevance = 0;
- session->total_hits = 0;
session->total_records = 0;
session->number_of_warnings_unknown_elements = 0;
session->number_of_warnings_unknown_metadata = 0;
@@ -857,13 +915,15 @@ struct session *new_session(NMEM nmem, struct conf_service *service,
return session;
}
-struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem)
+const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf);
+
+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++;
@@ -876,7 +936,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);
@@ -885,13 +945,24 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem)
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)++;
}
- 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)
{
@@ -909,6 +980,116 @@ 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;
+
+ 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;
+ 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;
+ 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");
+ }
+ }
+ }
+ }
+ tname = "xtargets";
+ if (num_names > 0 && !strcmp(names[j], tname))
+ {
+ 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)
{
@@ -976,6 +1157,8 @@ struct record_cluster **show_range_start(struct session *se,
}
else
{
+ struct client_list *l;
+
for (spp = sp; spp; spp = spp->next)
if (spp->type == Metadata_sortkey_relevance)
{
@@ -986,7 +1169,10 @@ struct record_cluster **show_range_start(struct session *se,
reclist_enter(se->reclist);
*total = reclist_get_num_records(se->reclist);
- *sumhits = se->total_hits;
+
+ *sumhits = 0;
+ for (l = se->clients; l; l = l->next)
+ *sumhits += client_get_hits(l->client);
for (i = 0; i < start; i++)
if (!reclist_read_record(se->reclist))
@@ -1029,11 +1215,13 @@ void statistics(struct session *se, struct statistics *stat)
int count = 0;
memset(stat, 0, sizeof(*stat));
+ stat->num_hits = 0;
for (l = se->clients; l; l = l->next)
{
struct client *cl = l->client;
if (!client_get_connection(cl))
stat->num_no_connection++;
+ stat->num_hits += client_get_hits(cl);
switch (client_get_state(cl))
{
case Client_Connecting: stat->num_connecting++; break;
@@ -1045,7 +1233,6 @@ void statistics(struct session *se, struct statistics *stat)
}
count++;
}
- stat->num_hits = se->total_hits;
stat->num_records = se->total_records;
stat->num_clients = count;
@@ -1125,15 +1312,15 @@ static int get_mergekey_from_doc(xmlDoc *doc, xmlNode *root, const char *name,
if (value)
{
const char *norm_str;
- pp2_relevance_token_t prt =
- pp2_relevance_tokenize(service->mergekey_pct);
+ pp2_charset_token_t prt =
+ pp2_charset_token_create(service->charsets, "mergekey");
- pp2_relevance_first(prt, (const char *) value, 0);
+ pp2_charset_token_first(prt, (const char *) value, 0);
if (wrbuf_len(norm_wr) > 0)
wrbuf_puts(norm_wr, " ");
wrbuf_puts(norm_wr, name);
while ((norm_str =
- pp2_relevance_token_next(prt)))
+ pp2_charset_token_next(prt)))
{
if (*norm_str)
{
@@ -1142,7 +1329,7 @@ static int get_mergekey_from_doc(xmlDoc *doc, xmlNode *root, const char *name,
}
}
xmlFree(value);
- pp2_relevance_token_destroy(prt);
+ pp2_charset_token_destroy(prt);
no_found++;
}
}
@@ -1164,11 +1351,11 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
if (mergekey)
{
const char *norm_str;
- pp2_relevance_token_t prt =
- pp2_relevance_tokenize(service->mergekey_pct);
+ pp2_charset_token_t prt =
+ pp2_charset_token_create(service->charsets, "mergekey");
- pp2_relevance_first(prt, (const char *) mergekey, 0);
- while ((norm_str = pp2_relevance_token_next(prt)))
+ pp2_charset_token_first(prt, (const char *) mergekey, 0);
+ while ((norm_str = pp2_charset_token_next(prt)))
{
if (*norm_str)
{
@@ -1177,7 +1364,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
wrbuf_puts(norm_wr, norm_str);
}
}
- pp2_relevance_token_destroy(prt);
+ pp2_charset_token_destroy(prt);
xmlFree(mergekey);
}
else
@@ -1205,8 +1392,13 @@ 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",
- client_get_database(cl)->database->url, record_no);
+ 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));
@@ -1310,7 +1502,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;
}
@@ -1324,7 +1516,7 @@ int ingest_record(struct client *cl, const char *rec,
}
session_enter(se);
if (client_get_session(cl) == se)
- ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm);
+ ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm);
session_leave(se);
xmlFreeDoc(xdoc);
@@ -1340,43 +1532,18 @@ static int ingest_to_cluster(struct client *cl,
xmlNode *n;
xmlChar *type = 0;
xmlChar *value = 0;
- struct session_database *sdb = client_get_database(cl);
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,
record_no);
- struct record_cluster *cluster = reclist_insert(se->reclist,
- service,
- record,
- mergekey_norm,
- &se->total_merged);
-
- const char *use_term_factor_str = session_setting_oneval(sdb, PZ_TERMLIST_TERM_FACTOR);
- int use_term_factor = 0;
- int term_factor = 1;
- if (use_term_factor_str && use_term_factor_str[0] != 0)
- use_term_factor = atoi(use_term_factor_str);
- if (use_term_factor) {
- 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 (!cluster)
- 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);
- relevance_newrec(se->relevance, cluster);
-
- // now parsing XML record and adding data to cluster or record metadata
for (n = root->children; n; n = n->next)
{
- pp2_relevance_token_t prt;
if (type)
xmlFree(type);
if (value)
@@ -1388,11 +1555,9 @@ static int ingest_to_cluster(struct client *cl,
if (!strcmp((const char *) n->name, "metadata"))
{
struct conf_metadata *ser_md = 0;
- struct conf_sortkey *ser_sk = 0;
struct record_metadata **wheretoput = 0;
struct record_metadata *rec_md = 0;
int md_field_id = -1;
- int sk_field_id = -1;
type = xmlGetProp(n, (xmlChar *) "type");
value = xmlNodeListGetString(xdoc, n->children, 1);
@@ -1412,13 +1577,8 @@ static int ingest_to_cluster(struct client *cl,
se->number_of_warnings_unknown_metadata++;
continue;
}
-
+
ser_md = &service->metadata[md_field_id];
-
- if (ser_md->sortkey_offset >= 0){
- sk_field_id = ser_md->sortkey_offset;
- ser_sk = &service->sortkeys[sk_field_id];
- }
// non-merged metadata
rec_md = record_metadata_init(se->nmem, (const char *) value,
@@ -1433,26 +1593,95 @@ static int ingest_to_cluster(struct client *cl,
while (*wheretoput)
wheretoput = &(*wheretoput)->next;
*wheretoput = rec_md;
+ }
+ }
+
+ cluster = reclist_insert(se->reclist, service, record,
+ mergekey_norm, &se->total_merged);
+ if (!cluster)
+ return -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));
+ }
+ }
+
+ if (global_parameters.dump_records)
+ session_log(se, YLOG_LOG, "Cluster id %s from %s (#%d)", cluster->recid,
+ sdb->database->id, record_no);
+
+
+ relevance_newrec(se->relevance, cluster);
+
+ // now parsing XML record and adding data to cluster or record metadata
+ for (n = root->children; n; n = n->next)
+ {
+ pp2_charset_token_t prt;
+ if (type)
+ xmlFree(type);
+ if (value)
+ xmlFree(value);
+ type = value = 0;
+
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) n->name, "metadata"))
+ {
+ struct conf_metadata *ser_md = 0;
+ struct conf_sortkey *ser_sk = 0;
+ struct record_metadata **wheretoput = 0;
+ struct record_metadata *rec_md = 0;
+ int md_field_id = -1;
+ int sk_field_id = -1;
+
+ type = xmlGetProp(n, (xmlChar *) "type");
+ value = xmlNodeListGetString(xdoc, n->children, 1);
+
+ if (!type || !value || !*value)
+ continue;
+
+ md_field_id
+ = conf_service_metadata_field_id(service, (const char *) type);
+ if (md_field_id < 0)
+ continue;
+
+ ser_md = &service->metadata[md_field_id];
+
+ if (ser_md->sortkey_offset >= 0)
+ {
+ sk_field_id = ser_md->sortkey_offset;
+ ser_sk = &service->sortkeys[sk_field_id];
+ }
// 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:
// assign cluster or record based on merge action
if (ser_md->merge == Metadata_merge_unique)
{
- struct record_metadata *mnode;
- for (mnode = *wheretoput; mnode; mnode = mnode->next)
- if (!strcmp((const char *) mnode->data.text.disp,
+ while (*wheretoput)
+ {
+ if (!strcmp((const char *) (*wheretoput)->data.text.disp,
rec_md->data.text.disp))
break;
- if (!mnode)
- {
- rec_md->next = *wheretoput;
- *wheretoput = rec_md;
+ wheretoput = &(*wheretoput)->next;
}
+ if (!*wheretoput)
+ *wheretoput = rec_md;
}
else if (ser_md->merge == Metadata_merge_longest)
{
@@ -1472,12 +1701,13 @@ static int ingest_to_cluster(struct client *cl,
nmem_malloc(se->nmem,
sizeof(union data_types));
- prt = pp2_relevance_tokenize(service->sort_pct);
+ prt =
+ pp2_charset_token_create(service->charsets, "sort");
- pp2_relevance_first(prt, rec_md->data.text.disp,
- skip_article);
+ pp2_charset_token_first(prt, rec_md->data.text.disp,
+ skip_article);
- pp2_relevance_token_next(prt);
+ pp2_charset_token_next(prt);
sort_str = pp2_get_sort(prt);
@@ -1491,13 +1721,14 @@ static int ingest_to_cluster(struct client *cl,
}
cluster->sortkeys[sk_field_id]->text.sort =
nmem_strdup(se->nmem, sort_str);
- pp2_relevance_token_destroy(prt);
+ pp2_charset_token_destroy(prt);
}
}
}
else if (ser_md->merge == Metadata_merge_all)
{
- rec_md->next = *wheretoput;
+ while (*wheretoput)
+ wheretoput = &(*wheretoput)->next;
*wheretoput = rec_md;
}
else if (ser_md->merge == Metadata_merge_range)