X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fsession.c;h=1927a1c13019ba20362af2f12b680080da038057;hb=b0797dd6ff756c6e7f66b0dc9f2848e0022cf1fb;hp=008a61773b90f98c475a0e89c7e1a80b28f90b4a;hpb=a61ae61f3abb9950f8f052caf91c76cda2a30c5b;p=pazpar2-moved-to-github.git diff --git a/src/session.c b/src/session.c index 008a617..1927a1c 100644 --- a/src/session.c +++ b/src/session.c @@ -56,7 +56,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include -#include #define USE_TIMING 0 #if USE_TIMING @@ -83,7 +82,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define MAX(a,b) ((a)>(b)?(a):(b)) // Note: Some things in this structure will eventually move to configuration -struct parameters global_parameters = +struct parameters global_parameters = { 0, // dump_records 0, // debug_mode @@ -149,14 +148,18 @@ static void log_xml_doc(xmlDoc *doc) xmlFree(result); } -static void session_enter(struct session *s) +static void session_enter(struct session *s, const char *caller) { + if (caller) + session_log(s, YLOG_DEBUG, "Session lock by %s", caller); yaz_mutex_enter(s->session_mutex); } -static void session_leave(struct session *s) +static void session_leave(struct session *s, const char *caller) { yaz_mutex_leave(s->session_mutex); + if (caller) + session_log(s, YLOG_DEBUG, "Session unlock by %s", caller); } static void session_normalize_facet(struct session *s, const char *type, @@ -211,7 +214,7 @@ void add_facet(struct session *s, const char *type, const char *value, int count WRBUF display_wrbuf = wrbuf_alloc(); session_normalize_facet(s, type, value, display_wrbuf, facet_wrbuf); - + if (wrbuf_len(facet_wrbuf)) { int i; @@ -227,12 +230,12 @@ void add_facet(struct session *s, const char *type, const char *value, int count wrbuf_destroy(display_wrbuf); return; } - + s->termlists[i].name = nmem_strdup(s->nmem, type); s->termlists[i].termlist = termlist_create(s->nmem); s->num_termlists = i + 1; } - + #if 0 session_log(s, YLOG_LOG, "Facets for %s: %s norm:%s (%d)", type, value, wrbuf_cstr(facet_wrbuf), count); #endif @@ -253,8 +256,7 @@ static xmlDoc *record_to_xml(struct session *se, if (!rdoc) { - session_log(se, YLOG_FATAL, "Non-wellformed XML received from %s", - db->id); + session_log(se, YLOG_WARN, "Non-wellformed XML"); return 0; } @@ -342,21 +344,20 @@ static xmlDoc *normalize_record(struct session *se, if (rdoc) { char *parms[MAX_XSLT_ARGS*2+1]; - + insert_settings_parameters(sdb, service, parms, nmem); - + if (normalize_record_transform(sdb->map, &rdoc, (const char **)parms)) { - session_log(se, YLOG_WARN, "Normalize failed from %s", - sdb->database->id); + session_log(se, YLOG_WARN, "Normalize failed"); } else { insert_settings_values(sdb, rdoc, service); - + if (global_parameters.dump_records) { - session_log(se, YLOG_LOG, "Normalized record from %s", + session_log(se, YLOG_LOG, "Normalized record from %s", sdb->database->id); log_xml_doc(rdoc); } @@ -410,10 +411,10 @@ static int prepare_map(struct session *se, struct session_database *sdb) const char *s; if (sdb->settings[PZ_XSLT] && - (s = session_setting_oneval(sdb, PZ_XSLT))) + (s = session_setting_oneval(sdb, PZ_XSLT))) { char auto_stylesheet[256]; - + if (!strcmp(s, "auto")) { const char *request_syntax = session_setting_oneval( @@ -458,31 +459,31 @@ static void session_watch_cancel(void *data, struct http_channel *c, } // set watch. Returns 0=OK, -1 if watch is already set -int session_set_watch(struct session *s, int what, +int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *chan) { int ret; - session_enter(s); + session_enter(s, "session_set_watch"); if (s->watchlist[what].fun) ret = -1; else { - + s->watchlist[what].fun = fun; s->watchlist[what].data = data; s->watchlist[what].obs = http_add_observer(chan, &s->watchlist[what], session_watch_cancel); ret = 0; } - session_leave(s); + session_leave(s, "session_set_watch"); return ret; } void session_alert_watch(struct session *s, int what) { assert(s); - session_enter(s); + session_enter(s, "session_alert_watch"); if (s->watchlist[what].fun) { /* our watch is no longer associated with http_channel */ @@ -499,13 +500,13 @@ void session_alert_watch(struct session *s, int what) s->watchlist[what].data = 0; s->watchlist[what].obs = 0; - session_leave(s); + session_leave(s, "session_alert_watch"); session_log(s, YLOG_DEBUG, "Alert Watch: %d calling function: %p", what, fun); fun(data); } else - session_leave(s); + session_leave(s,"session_alert_watch"); } //callback for grep_databases @@ -545,16 +546,16 @@ static void session_reset_active_clients(struct session *se, { struct client_list *l; - session_enter(se); + session_enter(se, "session_reset_active_clients"); l = se->clients_active; se->clients_active = new_list; - session_leave(se); + session_leave(se, "session_reset_active_clients"); while (l) { struct client_list *l_next = l->next; - client_lock(l->client); + client_lock(l->client); client_set_session(l->client, 0); /* mark client inactive */ client_unlock(l->client); @@ -569,10 +570,10 @@ static void session_remove_cached_clients(struct session *se) session_reset_active_clients(se, 0); - session_enter(se); + session_enter(se, "session_remove_cached_clients"); l = se->clients_cached; se->clients_cached = 0; - session_leave(se); + session_leave(se, "session_remove_cached_clients"); while (l) { @@ -588,7 +589,7 @@ static void session_remove_cached_clients(struct session *se) } // Associates a set of clients with a session; -// Note: Session-databases represent databases with per-session +// Note: Session-databases represent databases with per-session // setting overrides static int select_targets(struct session *se, const char *filter) { @@ -619,8 +620,7 @@ int session_is_preferred_clients_ready(struct session *s) return res == 0; } -static void session_clear_set(struct session *se, - const char *sort_field, int increasing, int position) +static void session_clear_set(struct session *se, struct reclist_sortparms *sp) { reclist_destroy(se->reclist); se->reclist = 0; @@ -630,64 +630,96 @@ static void session_clear_set(struct session *se, nmem_reset(se->nmem); 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->position = position; + se->sorted_results->name = nmem_strdup(se->nmem, sp->name); + se->sorted_results->increasing = sp->increasing; + se->sorted_results->type = sp->type; se->sorted_results->next = 0; - + + session_log(se, YLOG_DEBUG, "clear_set session_sort: field=%s increasing=%d type=%d configured", + sp->name, sp->increasing, sp->type); + se->reclist = reclist_create(se->nmem); } -void session_sort(struct session *se, const char *field, int increasing, - int position) +static void session_sort_unlocked(struct session *se, struct reclist_sortparms *sp) { - struct session_sorted_results *sr; + struct reclist_sortparms *sr; struct client_list *l; + const char *field = sp->name; + int increasing = sp->increasing; + int type = sp->type; + int clients_research = 0; - session_enter(se); - - yaz_log(YLOG_LOG, "session_sort field=%s increasing=%d position=%d", field, increasing, position); - /* see if we already have sorted for this critieria */ + yaz_log(YLOG_LOG, "session_sort field=%s increasing=%d type=%d", field, increasing, type); + /* see if we already have sorted for this criteria */ for (sr = se->sorted_results; sr; sr = sr->next) { - if (!strcmp(field, sr->field) && increasing == sr->increasing && sr->position == position) + if (!reclist_sortparms_cmp(sr,sp)) break; } if (sr) { - z(se, YLOG_DEBUG, "search_sort: field=%s increasing=%d position=%d already fetched", - field, increasing, position); - session_leave(se); + session_log(se, YLOG_DEBUG, "search_sort: field=%s increasing=%d type=%d already fetched", + field, increasing, type); return; } - if (position) + session_log(se, YLOG_DEBUG, "search_sort: field=%s increasing=%d type=%d must fetch", + field, increasing, type); + + // We need to reset reclist on every sort that changes the records, not just for position + // So if just one client requires new searching, we need to clear set. + // Ask each of the client if sorting requires re-search due to native sort + // If it does it will require us to + for (l = se->clients_active; l; l = l->next) { - session_clear_set(se, field, increasing, position); + struct client *cl = l->client; + // Assume no re-search is required. + client_parse_init(cl, 1); + clients_research += client_parse_sort(cl, sp); + } + if (clients_research) { + yaz_log(YLOG_DEBUG, "Reset results due to %d clients researching", clients_research); + session_clear_set(se, sp); } + else { + // A new sorting based on same record set + sr = nmem_malloc(se->nmem, sizeof(*sr)); + sr->name = nmem_strdup(se->nmem, field); + sr->increasing = increasing; + sr->type = type; + sr->next = se->sorted_results; + se->sorted_results = sr; + session_log(se, YLOG_DEBUG, "No research/ingesting done"); + return ; + } + session_log(se, YLOG_DEBUG, "Re- search/ingesting for clients due to change in sort order"); - session_log(se, YLOG_DEBUG, "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->position = position; - sr->next = se->sorted_results; - se->sorted_results = sr; - for (l = se->clients_active; l; l = l->next) { struct client *cl = l->client; if (client_get_state(cl) == Client_Connecting || client_get_state(cl) == Client_Idle || - client_get_state(cl) == Client_Working) + client_get_state(cl) == Client_Working) { client_start_search(cl); + } + else { + yaz_log(YLOG_DEBUG, "Client %s: No re-start/ingest in show. Wrong client state: %d", + client_get_id(cl), client_get_state(cl)); + } + } - session_leave(se); } +void session_sort(struct session *se, struct reclist_sortparms *sp) { + //session_enter(se, "session_sort"); + session_sort_unlocked(se, sp); + //session_leave(se, "session_sort"); +} + + enum pazpar2_error_code session_search(struct session *se, const char *query, const char *startrecs, @@ -695,84 +727,75 @@ enum pazpar2_error_code session_search(struct session *se, const char *filter, const char *limit, const char **addinfo, - const char *sort_field, int increasing) + struct reclist_sortparms *sp) { int live_channels = 0; int no_working = 0; int no_failed_query = 0; int no_failed_limit = 0; struct client_list *l, *l0; - struct timeval tval; facet_limits_t facet_limits; + int same_sort_order = 0; session_log(se, YLOG_DEBUG, "Search"); *addinfo = 0; - if (se->settings_modified) + if (se->settings_modified) { session_remove_cached_clients(se); + } else session_reset_active_clients(se, 0); - - session_enter(se); + + session_enter(se, "session_search"); se->settings_modified = 0; - session_clear_set(se, sort_field, increasing); + + if (se->sorted_results) { + if (!reclist_sortparms_cmp(se->sorted_results, sp)) + same_sort_order = 1; + } + session_clear_set(se, sp); relevance_destroy(&se->relevance); live_channels = select_targets(se, filter); if (!live_channels) { - session_leave(se); + session_leave(se, "session_search"); return PAZPAR2_NO_TARGETS; } - yaz_gettimeofday(&tval); - - tval.tv_sec += 5; - facet_limits = facet_limits_create(limit); if (!facet_limits) { *addinfo = "limit"; - session_leave(se); + session_leave(se, "session_search"); return PAZPAR2_MALFORMED_PARAMETER_VALUE; } l0 = se->clients_active; se->clients_active = 0; - session_leave(se); + session_leave(se, "session_search"); for (l = l0; l; l = l->next) { int parse_ret; struct client *cl = l->client; - + client_parse_init(cl, 1); if (prepare_map(se, client_get_database(cl)) < 0) continue; - parse_ret = client_parse_query(cl, query, facet_limits, startrecs, - maxrecs, se->service->ccl_bibset); + parse_ret = client_parse_query(cl, query, facet_limits, se->service->ccl_bibset); if (parse_ret == -1) no_failed_query++; else if (parse_ret == -2) no_failed_limit++; + else if (parse_ret < 0) + no_working++; /* other error, such as bad CCL map */ else { - int r = - client_prep_connection(cl, se->service->z3950_operation_timeout, - se->service->z3950_session_timeout, - se->service->server->iochan_man, - &tval); - if (parse_ret == 1 && r == 2) - { - session_log(se, YLOG_LOG, "client %s REUSE result", client_get_id(cl)); - client_reingest(cl); - } - else if (r) - { - session_log(se, YLOG_LOG, "client %s NEW search", client_get_id(cl)); - client_start_search(cl); - } + client_parse_range(cl, startrecs, maxrecs); + client_parse_sort(cl, sp); + client_start_search(cl); no_working++; } } @@ -806,7 +829,7 @@ static void session_init_databases_fun(void *context, struct database *db) int i; new->database = db; - + new->map = 0; assert(db->settings); new->settings = nmem_malloc(se->session_nmem, @@ -837,7 +860,7 @@ void session_init_databases(struct session *se) // Probably session_init_databases_fun should be refactored instead of // called here. -static struct session_database *load_session_database(struct session *se, +static struct session_database *load_session_database(struct session *se, char *id) { struct database *db = new_database_inherit_settings(id, se->session_nmem, se->service->settings); @@ -848,7 +871,7 @@ static struct session_database *load_session_database(struct session *se, } // Find an existing session database. If not found, load it -static struct session_database *find_session_database(struct session *se, +static struct session_database *find_session_database(struct session *se, char *id) { struct session_database *sdb; @@ -917,9 +940,9 @@ size_t session_get_memory_status(struct session *session) { size_t session_nmem; if (session == 0) return 0; - session_enter(session); + session_enter(session, "session_get_memory_status"); session_nmem = nmem_total(session->nmem); - session_leave(session); + session_leave(session, "session_get_memory_status"); return session_nmem; } @@ -949,6 +972,8 @@ struct session *new_session(NMEM nmem, struct conf_service *service, session->session_nmem = nmem; session->nmem = nmem_create(); session->databases = 0; + session->sorted_results = 0; + for (i = 0; i <= SESSION_WATCH_MAX; i++) { session->watchlist[i].data = 0; @@ -1006,9 +1031,9 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se, struct hitsbytarget *get_hitsbytarget(struct session *se, int *count, NMEM nmem) { struct hitsbytarget *p; - session_enter(se); + session_enter(se, "get_hitsbytarget"); p = hitsbytarget_nb(se, count, nmem); - session_leave(se); + session_leave(se, "get_hitsbytarget"); return p; } @@ -1043,20 +1068,20 @@ static int targets_termlist_nb(WRBUF wrbuf, struct session *se, int num, { // 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); @@ -1070,8 +1095,8 @@ static int targets_termlist_nb(WRBUF wrbuf, struct session *se, int num, wrbuf_puts(wrbuf, ""); wrbuf_xmlputs(wrbuf, ht[i].state); wrbuf_puts(wrbuf, "\n"); - - wrbuf_printf(wrbuf, "%d\n", + + wrbuf_printf(wrbuf, "%d\n", ht[i].diagnostic); wrbuf_puts(wrbuf, "\n"); } @@ -1091,7 +1116,7 @@ void perform_termlist(struct http_channel *c, struct session *se, nmem_strsplit(nmem_tmp, ",", name, &names, &num_names); - session_enter(se); + session_enter(se, "perform_termlist"); for (j = 0; j < num_names; j++) { @@ -1121,14 +1146,14 @@ void perform_termlist(struct http_channel *c, struct session *se, // 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", + + wrbuf_printf(c->wrbuf, + "%d", p[i]->frequency); wrbuf_puts(c->wrbuf, "\n"); } @@ -1154,7 +1179,7 @@ void perform_termlist(struct http_channel *c, struct session *se, wrbuf_puts(c->wrbuf, "\"/>\n"); } } - session_leave(se); + session_leave(se, "perform_termlist"); nmem_destroy(nmem_tmp); } @@ -1166,7 +1191,7 @@ void report_nmem_stats(void) nmem_get_memory_in_use(&in_use); nmem_get_memory_free(&is_free); - yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld", + yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld", (long) in_use, (long) is_free); } #endif @@ -1177,7 +1202,7 @@ struct record_cluster *show_single_start(struct session *se, const char *id, { struct record_cluster *r = 0; - session_enter(se); + session_enter(se, "show_single_start"); *prev_r = 0; *next_r = 0; if (se->reclist) @@ -1195,39 +1220,39 @@ struct record_cluster *show_single_start(struct session *se, const char *id, reclist_leave(se->reclist); } if (!r) - session_leave(se); + session_leave(se, "show_single_start"); return r; } void show_single_stop(struct session *se, struct record_cluster *rec) { - session_leave(se); + session_leave(se, "show_single_stop"); } struct record_cluster **show_range_start(struct session *se, - struct reclist_sortparms *sp, + struct reclist_sortparms *sp, int start, int *num, int *total, Odr_int *sumhits, Odr_int *approx_hits) { struct record_cluster **recs; struct reclist_sortparms *spp; int i; -#if USE_TIMING +#if USE_TIMING yaz_timing_t t = yaz_timing_create(); #endif - session_enter(se); + session_enter(se, "show_range_start"); recs = nmem_malloc(se->nmem, *num * sizeof(struct record_cluster *)); if (!se->relevance) { *num = 0; *total = 0; - *sumhits = 0; + *sumhits = 0; *approx_hits = 0; recs = 0; } else { struct client_list *l; - + for (spp = sp; spp; spp = spp->next) if (spp->type == Metadata_sortkey_relevance) { @@ -1235,7 +1260,7 @@ struct record_cluster **show_range_start(struct session *se, break; } reclist_sort(se->reclist, sp); - + reclist_enter(se->reclist); *total = reclist_get_num_records(se->reclist); @@ -1252,7 +1277,7 @@ struct record_cluster **show_range_start(struct session *se, recs = 0; break; } - + for (i = 0; i < *num; i++) { struct record_cluster *r = reclist_read_record(se->reclist); @@ -1267,7 +1292,7 @@ struct record_cluster **show_range_start(struct session *se, } #if USE_TIMING yaz_timing_stop(t); - yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f", + yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f", yaz_timing_get_real(t), yaz_timing_get_user(t), yaz_timing_get_sys(t)); yaz_timing_destroy(&t); @@ -1277,7 +1302,7 @@ struct record_cluster **show_range_start(struct session *se, void show_range_stop(struct session *se, struct record_cluster **recs) { - session_leave(se); + session_leave(se, "show_range_stop"); } void statistics(struct session *se, struct statistics *stat) @@ -1315,7 +1340,7 @@ static struct record_metadata *record_metadata_init( { struct record_metadata *rec_md = record_metadata_create(nmem); struct record_metadata_attr **attrp = &rec_md->attributes; - + for (; attr; attr = attr->next) { if (attr->children && attr->children->content) @@ -1340,7 +1365,7 @@ static struct record_metadata *record_metadata_init( char *p = nmem_strdup(nmem, value); p = normalize7bit_generic(p, " ,/.:(["); - + rec_md->data.text.disp = p; rec_md->data.text.sort = 0; } @@ -1385,7 +1410,7 @@ static int get_mergekey_from_doc(xmlDoc *doc, xmlNode *root, const char *name, const char *norm_str; pp2_charset_token_t prt = pp2_charset_token_create(service->charsets, "mergekey"); - + pp2_charset_token_first(prt, (const char *) value, 0); if (wrbuf_len(norm_wr) > 0) wrbuf_puts(norm_wr, " "); @@ -1451,7 +1476,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, service, norm_wr); if (r == 0 && ser_md->mergekey == Metadata_mergekey_required) { - /* no mergekey on this one and it is required.. + /* no mergekey on this one and it is required.. Generate unique key instead */ wrbuf_rewind(norm_wr); break; @@ -1477,7 +1502,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, return mergekey_norm; } -/** \brief see if metadata for pz:recordfilter exists +/** \brief see if metadata for pz:recordfilter exists \param root xml root element of normalized record \param sdb session database for client \retval 0 if there is no metadata for pz:recordfilter @@ -1486,7 +1511,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, If there is no pz:recordfilter defined, this function returns 1 as well. */ - + static int check_record_filter(xmlNode *root, struct session_database *sdb) { int match = 0; @@ -1564,19 +1589,19 @@ int ingest_record(struct client *cl, const char *rec, xmlDoc *xdoc = normalize_record(se, sdb, service, rec, nmem); xmlNode *root; const char *mergekey_norm; - + if (!xdoc) return -1; - + root = xmlDocGetRootElement(xdoc); - + if (!check_record_filter(root, sdb)) { session_log(se, YLOG_LOG, "Filtered out record no %d from %s", record_no, sdb->database->id); xmlFreeDoc(xdoc); return -2; } - + mergekey_norm = get_mergekey(xdoc, cl, record_no, service, nmem); if (!mergekey_norm) { @@ -1584,11 +1609,11 @@ int ingest_record(struct client *cl, const char *rec, xmlFreeDoc(xdoc); return -1; } - session_enter(se); + session_enter(se, "ingest_record"); if (client_get_session(cl) == se) ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm); - session_leave(se); - + session_leave(se, "ingest_record"); + xmlFreeDoc(xdoc); return ret; } @@ -1611,11 +1636,11 @@ static int check_limit_local(struct client *cl, int md_field_id; char **values = 0; int i, num_v = 0; - + const char *name = client_get_facet_limit_local(cl, sdb, &l, nmem_tmp, &num_v, &values); if (!name) break; - + md_field_id = conf_service_metadata_field_id(service, name); if (md_field_id < 0) { @@ -1629,11 +1654,11 @@ static int check_limit_local(struct client *cl, { if (rec_md) { - if (ser_md->type == Metadata_type_year + if (ser_md->type == Metadata_type_year || ser_md->type == Metadata_type_date) { int y = atoi(values[i]); - if (y >= rec_md->data.number.min + if (y >= rec_md->data.number.min && y <= rec_md->data.number.max) break; } @@ -1664,7 +1689,7 @@ static int check_limit_local(struct client *cl, nmem_destroy(nmem_tmp); return skip_record; } - + static int ingest_to_cluster(struct client *cl, xmlDoc *xdoc, xmlNode *root, @@ -1679,7 +1704,7 @@ static int ingest_to_cluster(struct client *cl, int term_factor = 1; struct record_cluster *cluster; struct session_database *sdb = client_get_database(cl); - struct record *record = record_create(se->nmem, + struct record *record = record_create(se->nmem, service->num_metadata, service->num_sortkeys, cl, record_no); @@ -1691,7 +1716,7 @@ static int ingest_to_cluster(struct client *cl, if (value) xmlFree(value); type = value = 0; - + if (n->type != XML_ELEMENT_NODE) continue; if (!strcmp((const char *) n->name, "metadata")) @@ -1700,26 +1725,26 @@ static int ingest_to_cluster(struct client *cl, struct record_metadata **wheretoput = 0; struct record_metadata *rec_md = 0; int md_field_id = -1; - + type = xmlGetProp(n, (xmlChar *) "type"); value = xmlNodeListGetString(xdoc, n->children, 1); - + if (!type || !value || !*value) continue; - - md_field_id + + md_field_id = conf_service_metadata_field_id(service, (const char *) type); if (md_field_id < 0) { if (se->number_of_warnings_unknown_metadata == 0) { - session_log(se, YLOG_WARN, + session_log(se, YLOG_WARN, "Ignoring unknown metadata element: %s", type); } se->number_of_warnings_unknown_metadata++; continue; } - + ser_md = &service->metadata[md_field_id]; // non-merged metadata @@ -1772,7 +1797,7 @@ static int ingest_to_cluster(struct client *cl, 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) { @@ -1782,7 +1807,7 @@ static int ingest_to_cluster(struct client *cl, if (value) xmlFree(value); type = value = 0; - + if (n->type != XML_ELEMENT_NODE) continue; if (!strcmp((const char *) n->name, "metadata")) @@ -1795,18 +1820,18 @@ static int ingest_to_cluster(struct client *cl, int sk_field_id = -1; const char *rank; xmlChar *xml_rank; - + type = xmlGetProp(n, (xmlChar *) "type"); value = xmlNodeListGetString(xdoc, n->children, 1); - + if (!type || !value || !*value) continue; - - md_field_id + + 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) @@ -1832,7 +1857,7 @@ static int ingest_to_cluster(struct client *cl, { while (*wheretoput) { - if (!strcmp((const char *) (*wheretoput)->data.text.disp, + if (!strcmp((const char *) (*wheretoput)->data.text.disp, rec_md->data.text.disp)) break; wheretoput = &(*wheretoput)->next; @@ -1842,22 +1867,22 @@ static int ingest_to_cluster(struct client *cl, } else if (ser_md->merge == Metadata_merge_longest) { - if (!*wheretoput - || strlen(rec_md->data.text.disp) + if (!*wheretoput + || strlen(rec_md->data.text.disp) > strlen((*wheretoput)->data.text.disp)) { *wheretoput = rec_md; if (ser_sk) { const char *sort_str = 0; - int skip_article = + int skip_article = ser_sk->type == Metadata_sortkey_skiparticle; if (!cluster->sortkeys[sk_field_id]) - cluster->sortkeys[sk_field_id] = - nmem_malloc(se->nmem, + cluster->sortkeys[sk_field_id] = + nmem_malloc(se->nmem, sizeof(union data_types)); - + prt = pp2_charset_token_create(service->charsets, "sort"); @@ -1865,18 +1890,18 @@ static int ingest_to_cluster(struct client *cl, skip_article); pp2_charset_token_next(prt); - + sort_str = pp2_get_sort(prt); - - cluster->sortkeys[sk_field_id]->text.disp = + + cluster->sortkeys[sk_field_id]->text.disp = rec_md->data.text.disp; if (!sort_str) { sort_str = rec_md->data.text.disp; - session_log(se, YLOG_WARN, + session_log(se, YLOG_WARN, "Could not make sortkey. Bug #1858"); } - cluster->sortkeys[sk_field_id]->text.sort = + cluster->sortkeys[sk_field_id]->text.sort = nmem_strdup(se->nmem, sort_str); pp2_charset_token_destroy(prt); } @@ -1894,7 +1919,7 @@ static int ingest_to_cluster(struct client *cl, { *wheretoput = rec_md; if (ser_sk) - cluster->sortkeys[sk_field_id] + cluster->sortkeys[sk_field_id] = &rec_md->data; } else @@ -1908,10 +1933,10 @@ static int ingest_to_cluster(struct client *cl, } } - // ranking of _all_ fields enabled ... + // ranking of _all_ fields enabled ... if (rank) { - relevance_countwords(se->relevance, cluster, + relevance_countwords(se->relevance, cluster, (char *) value, rank, ser_md->name); }