/* This file is part of Pazpar2.
- Copyright (C) 2006-2012 Index Data
+ Copyright (C) 2006-2013 Index Data
Pazpar2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
struct service_xslt *next;
};
-static void conf_metadata_assign(NMEM nmem,
- struct conf_metadata * metadata,
- const char *name,
- enum conf_metadata_type type,
- enum conf_metadata_merge merge,
- enum conf_setting_type setting,
- int brief,
- int termlist,
- const char *rank,
- int sortkey_offset,
- enum conf_metadata_mergekey mt,
- const char *facetrule,
- const char *limitmap)
+static char *xml_context(const xmlNode *ptr, char *res, size_t len)
{
- assert(nmem && metadata && name);
-
- metadata->name = nmem_strdup(nmem, name);
-
- metadata->type = type;
-
- // enforcing that type_year is always range_merge
- if (metadata->type == Metadata_type_year)
- metadata->merge = Metadata_merge_range;
- else
- metadata->merge = merge;
-
- metadata->setting = setting;
- metadata->brief = brief;
- metadata->termlist = termlist;
- metadata->rank = nmem_strdup_null(nmem, rank);
- metadata->sortkey_offset = sortkey_offset;
- metadata->mergekey = mt;
- metadata->facetrule = nmem_strdup_null(nmem, facetrule);
- metadata->limitmap = nmem_strdup_null(nmem, limitmap);
-}
-
+ size_t off = len - 1;
+ res[off] = '\0';
+ while (ptr && ptr->type == XML_ELEMENT_NODE)
+ {
+ size_t l = strlen((const char *) ptr->name);
+ if (off <= l + 1)
+ break;
-static void conf_sortkey_assign(NMEM nmem,
- struct conf_sortkey * sortkey,
- const char *name,
- enum conf_sortkey_type type)
-{
- assert(nmem && sortkey && name);
+ off = off - l;
+ memcpy(res + off, ptr->name, l);
+ res[--off] = '/';
- sortkey->name = nmem_strdup(nmem, name);
- sortkey->type = type;
+ ptr = ptr->parent;
+ }
+ return res + off;
}
struct conf_service *service_init(struct conf_server *server,
service->z3950_operation_timeout = 30;
service->rank_cluster = 1;
service->rank_debug = 0;
+ service->rank_follow = 0.0;
+ service->rank_lead = 0.0;
+ service->rank_length = 2;
service->charsets = 0;
int sortkey_offset,
enum conf_metadata_mergekey mt,
const char *facetrule,
- const char *limitmap
+ const char *limitmap,
+ const char *limitcluster
)
{
struct conf_metadata * md = 0;
+ NMEM nmem = service->nmem;
- if (!service || !service->metadata || !service->num_metadata
+ if (!service->metadata || !service->num_metadata
|| field_id < 0 || !(field_id < service->num_metadata))
return 0;
md = service->metadata + field_id;
- conf_metadata_assign(service->nmem, md, name, type, merge, setting,
- brief, termlist, rank, sortkey_offset,
- mt, facetrule, limitmap);
+ assert(nmem && md && name);
+
+ md->name = nmem_strdup(nmem, name);
+
+ md->type = type;
+
+ // enforcing that type_year is always range_merge
+ if (md->type == Metadata_type_year)
+ md->merge = Metadata_merge_range;
+ else
+ md->merge = merge;
+
+ md->setting = setting;
+ md->brief = brief;
+ md->termlist = termlist;
+ md->rank = nmem_strdup_null(nmem, rank);
+ md->sortkey_offset = sortkey_offset;
+ md->mergekey = mt;
+ md->facetrule = nmem_strdup_null(nmem, facetrule);
+ md->limitmap = nmem_strdup_null(nmem, limitmap);
+ md->limitcluster = nmem_strdup_null(nmem, limitcluster);
return md;
}
-static struct conf_sortkey * conf_service_add_sortkey(
+static struct conf_sortkey *conf_service_add_sortkey(
struct conf_service *service,
int field_id,
const char *name,
enum conf_sortkey_type type)
{
- struct conf_sortkey * sk = 0;
+ struct conf_sortkey *sk = 0;
+ NMEM nmem = service->nmem;
- if (!service || !service->sortkeys || !service->num_sortkeys
+ if (!service->sortkeys || !service->num_sortkeys
|| field_id < 0 || !(field_id < service->num_sortkeys))
return 0;
- //sk = &((service->sortkeys)[field_id]);
sk = service->sortkeys + field_id;
- conf_sortkey_assign(service->nmem, sk, name, type);
+ assert(nmem && sk && name);
+
+ sk->name = nmem_strdup(nmem, name);
+ sk->type = type;
return sk;
}
xmlChar *xml_setting = 0;
xmlChar *xml_mergekey = 0;
xmlChar *xml_limitmap = 0;
+ xmlChar *xml_limitcluster = 0;
xmlChar *xml_icu_chain = 0;
struct _xmlAttr *attr;
+
+ assert(service);
+
for (attr = n->properties; attr; attr = attr->next)
{
if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
else if (!xmlStrcmp(attr->name, BAD_CAST "limitmap") &&
attr->children && attr->children->type == XML_TEXT_NODE)
xml_limitmap = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "limitcluster") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_limitcluster = attr->children->content;
else
{
yaz_log(YLOG_FATAL, "Unknown metadata attribute '%s'", attr->name);
merge = Metadata_merge_range;
else if (!strcmp((const char *) xml_merge, "all"))
merge = Metadata_merge_all;
+ else if (!strcmp((const char *) xml_merge, "first"))
+ merge = Metadata_merge_first;
else
{
yaz_log(YLOG_FATAL,
(const char *) xml_rank, sortkey_offset,
mergekey_type,
(const char *) xml_icu_chain,
- (const char *) xml_limitmap);
+ (const char *) xml_limitmap,
+ (const char *) xml_limitcluster);
(*md_node)++;
return 0;
}
if (service_xslt_config(service, n))
return 0;
}
- else if (!strcmp((const char *) n->name, (const char *) "set"))
- {
- xmlChar *name= xmlGetProp(n, (xmlChar *) "name");
- xmlChar *value = xmlGetProp(n, (xmlChar *) "value");
- if (service->dictionary && name && value) {
- yaz_log(YLOG_DEBUG, "service set: %s=%s (Not implemented)", (char *) name, (char *) value);
- //service_aply_setting(service, name, value);
- }
- }
else if (!strcmp((const char *) n->name, "rank"))
{
char *rank_cluster = (char *) xmlGetProp(n, (xmlChar *) "cluster");
char *rank_debug = (char *) xmlGetProp(n, (xmlChar *) "debug");
+ char *rank_follow = (char *) xmlGetProp(n, (xmlChar *) "follow");
+ char *rank_lead = (char *) xmlGetProp(n, (xmlChar *) "lead");
+ char *rank_length= (char *) xmlGetProp(n, (xmlChar *) "length");
if (rank_cluster)
{
if (!strcmp(rank_cluster, "yes"))
return 0;
}
}
+ if (rank_follow)
+ {
+ service->rank_follow = atof(rank_follow);
+ }
+ if (rank_lead)
+ {
+ service->rank_lead = atof(rank_lead);
+ }
+ if (rank_length)
+ {
+ if (!strcmp(rank_length, "linear"))
+ service->rank_length = 2;
+ else if (!strcmp(rank_length, "log"))
+ service->rank_length = 1;
+ else if (!strcmp(rank_length, "none"))
+ service->rank_length = 0;
+ else
+ {
+ yaz_log(YLOG_FATAL, "service: rank@length linear|log|none");
+ return 0;
+ }
+ }
xmlFree(rank_cluster);
xmlFree(rank_debug);
+ xmlFree(rank_follow);
+ xmlFree(rank_lead);
+ xmlFree(rank_length);
}
else if (!strcmp((const char *) n->name, "sort-default"))
{
}
else
{
- yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+ char tmp[80];
+ yaz_log(YLOG_FATAL, "Bad element: %s . Context: %s", n->name,
+ xml_context(n, tmp, sizeof tmp));
return 0;
}
}
struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
xmlChar *server_id = xmlGetProp(node, (xmlChar *) "id");
- server->host = 0;
+ server->host = "@";
server->port = 0;
server->proxy_host = 0;
server->proxy_port = 0;
{
xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
+
if (port)
- server->port = atoi((const char *) port);
+ server->port = nmem_strdup(nmem, (const char *) port);
if (host)
server->host = nmem_strdup(nmem, (const char *) host);
+
xmlFree(port);
xmlFree(host);
}
return 0;
}
}
+ if (!server->port)
+ {
+ yaz_log(YLOG_FATAL, "No listening port given");
+ return 0;
+ }
if (server->service)
{
struct conf_service *s;
conf->iochan_man = iochan_man_create(conf->no_threads);
for (ser = conf->servers; ser; ser = ser->next)
{
- WRBUF w = wrbuf_alloc();
+ WRBUF w;
int r;
ser->iochan_man = conf->iochan_man;
if (listener_override)
{
- wrbuf_puts(w, listener_override);
- listener_override = 0; /* only first server is overriden */
- }
- else
- {
- if (ser->host)
- wrbuf_puts(w, ser->host);
- if (ser->port)
+ const char *cp = strrchr(listener_override, ':');
+ if (cp)
{
- if (wrbuf_len(w))
- wrbuf_puts(w, ":");
- wrbuf_printf(w, "%d", ser->port);
+ ser->host = nmem_strdupn(conf->nmem, listener_override,
+ cp - listener_override);
+ ser->port = nmem_strdup(conf->nmem, cp + 1);
+ }
+ else
+ {
+ ser->host = "@";
+ ser->port = nmem_strdup(conf->nmem, listener_override);
}
+ listener_override = 0; /* only first server is overriden */
}
- r = http_init(wrbuf_cstr(w), ser, record_fname);
- wrbuf_destroy(w);
+ r = http_init(ser, record_fname);
if (r)
return -1;