-/* $Id: config.c,v 1.38 2007-07-25 11:00:26 adam Exp $
+/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.38 2007-07-25 11:00:26 adam Exp $ */
+/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $ */
#include <string.h>
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
+ enum conf_setting_type setting,
int brief,
int termlist,
int rank,
else
metadata->merge = merge;
+ metadata->setting = setting;
metadata->brief = brief;
metadata->termlist = termlist;
metadata->rank = rank;
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
+ enum conf_setting_type setting,
int brief,
int termlist,
int rank,
//md = &((service->metadata)[field_id]);
md = service->metadata + field_id;
- md = conf_metadata_assign(nmem, md, name, type, merge,
+ md = conf_metadata_assign(nmem, md, name, type, merge, setting,
brief, termlist, rank, sortkey_offset);
return md;
}
xmlChar *xml_type = xmlGetProp(n, (xmlChar *) "type");
xmlChar *xml_termlist = xmlGetProp(n, (xmlChar *) "termlist");
xmlChar *xml_rank = xmlGetProp(n, (xmlChar *) "rank");
+ xmlChar *xml_setting = xmlGetProp(n, (xmlChar *) "setting");
enum conf_metadata_type type = Metadata_type_generic;
enum conf_metadata_merge merge = Metadata_merge_no;
+ enum conf_setting_type setting = Metadata_setting_no;
+ enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
int brief = 0;
int termlist = 0;
int rank = 0;
int sortkey_offset = 0;
- enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
// now do the parsing logic
if (!xml_name)
else
merge = Metadata_merge_no;
+ if (xml_setting)
+ {
+ if (!strcmp((const char *) xml_setting, "no"))
+ setting = Metadata_setting_no;
+ else if (!strcmp((const char *) xml_setting, "postproc"))
+ setting = Metadata_setting_postproc;
+ else if (!strcmp((const char *) xml_setting, "parameter"))
+ setting = Metadata_setting_no;
+ else
+ {
+ yaz_log(YLOG_FATAL,
+ "Unknown value for medadata/setting: %s", xml_setting);
+ return 0;
+ }
+ }
+
// add a sortkey if so specified
if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
{
// metadata known, assign values
conf_service_add_metadata(nmem, service, md_node,
(const char *) xml_name,
- type, merge,
+ type, merge, setting,
brief, termlist, rank, sortkey_offset);
xmlFree(xml_name);
-/* $Id: config.h,v 1.25 2007-06-08 13:58:46 adam Exp $
+/* $Id: config.h,v 1.26 2007-07-30 11:52:08 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
Metadata_sortkey_string // Flat string
};
-
+// This controls the ability to insert 'static' values from settings into retrieval recs
+enum conf_setting_type {
+ Metadata_setting_no,
+ Metadata_setting_postproc, // Insert setting value into normalized record
+ Metadata_setting_parameter // Expose value to normalization stylesheets
+};
// Describes known metadata elements and how they are to be manipulated
// An array of these structure provides a 'map' against which
// into service/record_cluster->sortkey array
enum conf_metadata_type type;
enum conf_metadata_merge merge;
+ enum conf_setting_type setting; // Value is to be taken from session/db settings?
};
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
+ enum conf_setting_type setting,
int brief,
int termlist,
int rank,
struct conf_service * conf_service_create(NMEM nmem,
int num_metadata, int num_sortkeys);
+
struct conf_metadata* conf_service_add_metadata(NMEM nmem,
struct conf_service *service,
int field_id,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
+ enum conf_setting_type setting,
int brief,
int termlist,
int rank,
-/* $Id: logic.c,v 1.56 2007-07-25 11:41:32 adam Exp $
+/* $Id: logic.c,v 1.57 2007-07-30 11:52:08 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
return rdoc;
}
+// Add static values from session database settings if applicable
+static void insert_settings_values(struct session_database *sdb, xmlDoc *doc)
+{
+ struct conf_service *service = global_parameters.server->service;
+ int i;
+
+ for (i = 0; i < service->num_metadata; i++)
+ {
+ struct conf_metadata *md = &service->metadata[i];
+ int offset;
+
+ if (md->setting == Metadata_setting_postproc &&
+ (offset = settings_offset(md->name)) > 0)
+ {
+ char *val = session_setting_oneval(sdb, offset);
+ if (val)
+ {
+ xmlNode *r = xmlDocGetRootElement(doc);
+ xmlNode *n = xmlNewTextChild(r, 0, (xmlChar *) "metadata",
+ (xmlChar *) val);
+ xmlSetProp(n, (xmlChar *) "type", (xmlChar *) md->name);
+ }
+ }
+ }
+}
+
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){
+ for (m = sdb->map; m; m = m->next)
+ {
xmlDoc *new = 0;
{
xmlFreeDoc(rdoc);
rdoc = new;
}
+
+ insert_settings_values(sdb, rdoc);
+
if (global_parameters.dump_records)
{
FILE *lf = yaz_log_file();
<?xml version="1.0" encoding="UTF-8"?>
<pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
-<!-- $Id: test_http.cfg,v 1.3 2007-07-18 13:39:11 adam Exp $ -->
+<!-- $Id: test_http.cfg,v 1.4 2007-07-30 11:52:08 quinn Exp $ -->
<!-- Used by test_http.sh -->
<server>
<listen port="9763"/>
<metadata name="id"/>
<metadata name="lccn" merge="unique"/>
<metadata name="description" brief="yes" merge="longest" rank="3"/>
+
+ <metadata name="test-usersetting" brief="yes" setting="postproc"/>
</service>
</server>
<settings target="z3950.indexdata.com/marc">
<!-- Used by test test_http.sh -->
- <!-- $Id: test_http.xml,v 1.3 2007-07-18 13:39:11 adam Exp $ -->
+ <!-- $Id: test_http.xml,v 1.4 2007-07-30 11:52:08 quinn Exp $ -->
<set name="pz:name" value="Local Test"/>
<set name="pz:nativesyntax" value="iso2709"/>
<set name="pz:xslt" value="auto"/>
+ <!-- Example of application-specific setting -->
+ <!-- Available in output record and/or normalization stylesheet -->
+ <set name="test-usersetting" value="XXXXXXXXXX"/>
+
</settings>
<md-title>How to program a computer</md-title>
<md-author>Jack Collins</md-author>
<md-id>11224467</md-id>
-<md-lccn>11224467</md-lccn></location>
+<md-lccn>11224467</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting></location>
<location id="z3950.indexdata.com/marc" name="Local Test">
<md-title>How to program a computer</md-title>
<md-author>Jack Collins</md-author>
<md-id>11224466</md-id>
-<md-lccn>11224466</md-lccn></location>
+<md-lccn>11224466</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting></location>
</record>