X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Flogic.c;h=e131fb37d17592c0f05720395011b601726b0fce;hb=52793fbdcc6099f1c86e0b4c2c918767c22f7bcc;hp=bb10b7861d68118b994cda5febd6bbf0f815730a;hpb=ae90eb71259064515a5d778cf23bc0dd474469ff;p=pazpar2-moved-to-github.git diff --git a/src/logic.c b/src/logic.c index bb10b78..e131fb3 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.34 2007-06-01 10:38:08 adam Exp $ +/* $Id: logic.c,v 1.47 2007-06-28 09:36:10 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -45,9 +45,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#if YAZ_VERSIONL >= 0x020163 #include -#endif #if HAVE_CONFIG_H #include "cconfig.h" @@ -72,6 +70,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "settings.h" #include "normalize7bit.h" +#define TERMLIST_HIGH_SCORE 25 + #define MAX_CHUNK 15 // Note: Some things in this structure will eventually move to configuration @@ -79,8 +79,7 @@ struct parameters global_parameters = { "", "", - "", - "", + "", 0, 0, /* dump_records */ 0, /* debug_mode */ @@ -144,15 +143,15 @@ static void add_facet(struct session *s, const char *type, const char *value) s->termlists[i].name = nmem_strdup(s->nmem, type); s->termlists[i].termlist - = termlist_create(s->nmem, s->expected_maxrecs, 15); + = termlist_create(s->nmem, s->expected_maxrecs, + TERMLIST_HIGH_SCORE); s->num_termlists = i + 1; } termlist_insert(s->termlists[i].termlist, value); } -xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) +xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec) { - struct database_retrievalmap *m; struct database *db = sdb->database; xmlDoc *rdoc = 0; const Odr_oid *oid = rec->direct_reference; @@ -231,36 +230,45 @@ xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) xmlDocDump(stderr, rdoc); #endif } + return rdoc; +} - for (m = sdb->map; m; m = m->next){ - xmlDoc *new = 0; - - { - xmlNodePtr root = 0; - new = xsltApplyStylesheet(m->stylesheet, rdoc, 0); - root= xmlDocGetRootElement(new); - if (!new || !root || !(root->children)) - { - yaz_log(YLOG_WARN, "XSLT transformation failed from %s", - sdb->database->url); - xmlFreeDoc(new); +xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) +{ + struct database_retrievalmap *m; + xmlDoc *rdoc = record_to_xml(sdb, rec); + if (rdoc) + { + for (m = sdb->map; m; m = m->next){ + xmlDoc *new = 0; + + { + xmlNodePtr root = 0; + new = xsltApplyStylesheet(m->stylesheet, rdoc, 0); + root= xmlDocGetRootElement(new); + if (!new || !root || !(root->children)) + { + yaz_log(YLOG_WARN, "XSLT transformation failed from %s", + sdb->database->url); + xmlFreeDoc(new); + xmlFreeDoc(rdoc); + return 0; + } + } + xmlFreeDoc(rdoc); - return 0; - } + rdoc = new; } - - xmlFreeDoc(rdoc); - rdoc = new; - } - if (global_parameters.dump_records) - { - fprintf(stderr, "Record from %s\n----------------\n", - sdb->database->url); + if (global_parameters.dump_records) + { + fprintf(stderr, "Record from %s\n----------------\n", + sdb->database->url); #if LIBXML_VERSION >= 20600 - xmlDocFormatDump(stderr, rdoc, 1); + xmlDocFormatDump(stderr, rdoc, 1); #else - xmlDocDump(stderr, rdoc); + xmlDocDump(stderr, rdoc); #endif + } } return rdoc; } @@ -339,7 +347,7 @@ static int prepare_map(struct session *se, struct session_database *sdb) (*m)->next = 0; if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i]))) { - yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s", + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load stylesheet: %s", stylesheets[i]); return -1; } @@ -376,21 +384,39 @@ static int prepare_session_database(struct session *se, 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) +{ + struct session_watchentry *ent = data; + + ent->fun = 0; + ent->data = 0; + ent->obs = 0; +} -void session_set_watch(struct session *s, int what, - session_watchfun fun, void *data) +// set watch. Returns 0=OK, -1 if watch is already set +int session_set_watch(struct session *s, int what, + session_watchfun fun, void *data, + struct http_channel *chan) { + if (s->watchlist[what].fun) + return -1; s->watchlist[what].fun = fun; s->watchlist[what].data = data; + s->watchlist[what].obs = http_add_observer(chan, &s->watchlist[what], + session_watch_cancel); + return 0; } void session_alert_watch(struct session *s, int what) { if (!s->watchlist[what].fun) return; + http_remove_observer(s->watchlist[what].obs); (*s->watchlist[what].fun)(s->watchlist[what].data); s->watchlist[what].fun = 0; s->watchlist[what].data = 0; + s->watchlist[what].obs = 0; } //callback for grep_databases @@ -466,7 +492,9 @@ static struct database_criterion *parse_filter(NMEM m, const char *buf) return res; } -char *search(struct session *se, char *query, char *filter) +enum pazpar2_error_code search(struct session *se, + char *query, char *filter, + const char **addinfo) { int live_channels = 0; struct client *cl; @@ -474,6 +502,7 @@ char *search(struct session *se, char *query, char *filter) yaz_log(YLOG_DEBUG, "Search"); + *addinfo = 0; nmem_reset(se->nmem); criteria = parse_filter(se->nmem, filter); se->requestid++; @@ -488,25 +517,29 @@ char *search(struct session *se, char *query, char *filter) se->expected_maxrecs = maxrecs; } else - return "NOTARGETS"; + return PAZPAR2_NO_TARGETS; se->relevance = 0; for (cl = se->clients; cl; cl = client_next_in_session(cl)) { if (prepare_session_database(se, client_get_database(cl)) < 0) - return "CONFIG_ERROR"; + { + *addinfo = client_get_database(cl)->database->url; + return PAZPAR2_CONFIG_TARGET; + } // Query must parse for all targets - if (client_parse_query(cl, query) < 0) - return "QUERY"; + if (client_parse_query(cl, query) < 0) + { + *addinfo = "query"; + return PAZPAR2_MALFORMED_PARAMETER_VALUE; + } } for (cl = se->clients; cl; cl = client_next_in_session(cl)) - { client_prep_connection(cl); - } - return 0; + return PAZPAR2_NO_ERROR; } // Creates a new session_database object for a database @@ -561,7 +594,7 @@ static void session_database_destroy(struct session_database *sdb) void session_init_databases(struct session *se) { se->databases = 0; - grep_databases(se, 0, session_init_databases_fun); + predef_grep_databases(se, 0, session_init_databases_fun); } // Probably session_init_databases_fun should be refactored instead of @@ -642,7 +675,6 @@ void destroy_session(struct session *s) { struct session_database *sdb; - yaz_log(YLOG_LOG, "Destroying session"); while (s->clients) client_destroy(s->clients); for (sdb = s->databases; sdb; sdb = sdb->next) @@ -658,6 +690,7 @@ struct session *new_session(NMEM nmem) yaz_log(YLOG_DEBUG, "New Pazpar2 session"); + session->relevance = 0; session->total_hits = 0; session->total_records = 0; session->num_termlists = 0; @@ -668,7 +701,7 @@ struct session *new_session(NMEM nmem) session->session_nmem = nmem; session->nmem = nmem_create(); session->wrbuf = wrbuf_alloc(); - session_init_databases(session); + session->databases = 0; for (i = 0; i <= SESSION_WATCH_MAX; i++) { session->watchlist[i].data = 0; @@ -747,34 +780,44 @@ struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, yaz_timing_t t = yaz_timing_create(); #endif - for (spp = sp; spp; spp = spp->next) - if (spp->type == Metadata_sortkey_relevance) - { - relevance_prepare_read(s->relevance, s->reclist); - break; - } - reclist_sort(s->reclist, sp); - - *total = s->reclist->num_records; - *sumhits = s->total_hits; - - for (i = 0; i < start; i++) - if (!reclist_read_record(s->reclist)) - { - *num = 0; - recs = 0; - break; - } - - for (i = 0; i < *num; i++) + if (!s->relevance) { - struct record_cluster *r = reclist_read_record(s->reclist); - if (!r) + *num = 0; + *total = 0; + *sumhits = 0; + recs = 0; + } + else + { + for (spp = sp; spp; spp = spp->next) + if (spp->type == Metadata_sortkey_relevance) + { + relevance_prepare_read(s->relevance, s->reclist); + break; + } + reclist_sort(s->reclist, sp); + + *total = s->reclist->num_records; + *sumhits = s->total_hits; + + for (i = 0; i < start; i++) + if (!reclist_read_record(s->reclist)) + { + *num = 0; + recs = 0; + break; + } + + for (i = 0; i < *num; i++) { - *num = i; - break; + struct record_cluster *r = reclist_read_record(s->reclist); + if (!r) + { + *num = i; + break; + } + recs[i] = r; } - recs[i] = r; } #if USE_TIMING yaz_timing_stop(t); @@ -858,38 +901,6 @@ void start_proxy(void) http_set_proxyaddr(hp, ser->myurl ? ser->myurl : ""); } -void start_zproxy(void) -{ - struct conf_server *ser = global_parameters.server; - - if (*global_parameters.zproxy_override){ - yaz_log(YLOG_LOG, "Z39.50 proxy %s", - global_parameters.zproxy_override); - return; - } - - else if (ser->zproxy_host || ser->zproxy_port) - { - char hp[128] = ""; - - strcpy(hp, ser->zproxy_host ? ser->zproxy_host : ""); - if (ser->zproxy_port) - { - if (*hp) - strcat(hp, ":"); - else - strcat(hp, "@:"); - - sprintf(hp + strlen(hp), "%d", ser->zproxy_port); - } - strcpy(global_parameters.zproxy_override, hp); - yaz_log(YLOG_LOG, "Z39.50 proxy %s", - global_parameters.zproxy_override); - - } - else - return; -} // Master list of connections we're handling events to static IOCHAN channel_list = 0; @@ -929,8 +940,8 @@ struct record *ingest_record(struct client *cl, Z_External *rec, } record = record_create(se->nmem, - service->num_metadata, service->num_sortkeys); - record_assign_client(record, cl); + service->num_metadata, service->num_sortkeys, cl, + record_no); mergekey_norm = (xmlChar *) nmem_strdup(se->nmem, (char*) mergekey); xmlFree(mergekey); @@ -974,7 +985,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, int first, last; type = xmlGetProp(n, (xmlChar *) "type"); - value = xmlNodeListGetString(xdoc, n->children, 0); + value = xmlNodeListGetString(xdoc, n->children, 1); if (!type || !value) continue;