From 5df65a405a33891391adbc7cca0c270949b4f0ef Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 20 Apr 2007 04:32:33 +0000 Subject: [PATCH] Allows definition/override of pz:cclmap:* settings via settings ws. CCL parser allocated/deallocated on the fly at query time --- src/database.c | 27 +-------------------------- src/logic.c | 33 +++++++++++++++++++++++++++++++-- src/pazpar2.h | 3 +-- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/database.c b/src/database.c index 70e556a..2ca3af5 100644 --- a/src/database.c +++ b/src/database.c @@ -1,4 +1,4 @@ -/* $Id: database.c,v 1.19 2007-04-18 12:41:38 quinn Exp $ +/* $Id: database.c,v 1.20 2007-04-20 04:32:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -165,7 +165,6 @@ static struct database *load_database(const char *id) db->explain = explain; db->settings = 0; db->next = databases; - db->ccl_map = 0; db->yaz_marc = 0; db->map = 0; databases = db; @@ -288,29 +287,6 @@ int grep_databases(void *context, struct database_criterion *cl, return i; } -// Initialize CCL map for a target -// Note: This approach ignores user-specific CCL maps, for which I -// don't presently see any application. -static void prepare_cclmap(void *ignore, struct database *db) -{ - struct setting *s; - - if (!db->settings) - return; - db->ccl_map = ccl_qual_mk(); - for (s = db->settings[PZ_CCLMAP]; s; s = s->next) - { - char *p = strchr(s->name + 3, ':'); - if (!p) - { - yaz_log(YLOG_FATAL, "Malformed cclmap name: %s", s->name); - exit(1); - } - p++; - ccl_qual_fitem(db->ccl_map, s->value, p); - } -} - // Initialize YAZ Map structures for MARC-based targets static void prepare_yazmarc(void *ignore, struct database *db) { @@ -377,7 +353,6 @@ static void prepare_map(void *ignore, struct database *db) // Read settings for each database, and prepare support data structures void prepare_databases(void) { - grep_databases(0, 0, prepare_cclmap); grep_databases(0, 0, prepare_yazmarc); grep_databases(0, 0, prepare_map); } diff --git a/src/logic.c b/src/logic.c index a9a4733..3cc1a23 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.11 2007-04-20 04:08:14 quinn Exp $ +/* $Id: logic.c,v 1.12 2007-04-20 04:32:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -1248,14 +1248,43 @@ static int client_prep_connection(struct client *cl) return 0; } +// Initialize CCL map for a target +static CCL_bibset prepare_cclmap(struct client *cl) +{ + struct session_database *sdb = cl->database; + struct setting *s; + CCL_bibset res; + + if (!sdb->settings) + return 0; + res = ccl_qual_mk(); + for (s = sdb->settings[PZ_CCLMAP]; s; s = s->next) + { + char *p = strchr(s->name + 3, ':'); + if (!p) + { + yaz_log(YLOG_WARN, "Malformed cclmap name: %s", s->name); + ccl_qual_rm(&res); + return 0; + } + p++; + ccl_qual_fitem(res, s->value, p); + } + return res; +} + // Parse the query given the settings specific to this client static int client_parse_query(struct client *cl, const char *query) { struct session *se = cl->session; struct ccl_rpn_node *cn; int cerror, cpos; + CCL_bibset ccl_map = prepare_cclmap(cl); - cn = ccl_find_str(cl->database->database->ccl_map, query, &cerror, &cpos); + if (!ccl_map) + return -1; + cn = ccl_find_str(ccl_map, query, &cerror, &cpos); + ccl_qual_rm(&ccl_map); if (!cn) { cl->state = Client_Error; diff --git a/src/pazpar2.h b/src/pazpar2.h index 1e098f3..d111196 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.27 2007-04-20 04:08:14 quinn Exp $ +/* $Id: pazpar2.h,v 1.28 2007-04-20 04:32:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -92,7 +92,6 @@ struct database { struct zr_explain *explain; struct setting **settings; struct database *next; - CCL_bibset ccl_map; yaz_marc_t yaz_marc; struct database_retrievalmap *map; }; -- 1.7.10.4