From: Sebastian Hammer Date: Tue, 9 Jan 2007 18:06:28 +0000 (+0000) Subject: Added date support (md-date in show command). X-Git-Tag: before.append.child~9 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=27dcdf6c67089a86b0f9759d9dfdbd85093ca32f;p=pazpar2-moved-to-github.git Added date support (md-date in show command). --- diff --git a/etc/marc21.xsl b/etc/marc21.xsl index cd20702..344a6c5 100644 --- a/etc/marc21.xsl +++ b/etc/marc21.xsl @@ -22,13 +22,11 @@ - diff --git a/etc/pazpar2.cfg b/etc/pazpar2.cfg index 6c14bc3..3ea7efa 100644 --- a/etc/pazpar2.cfg +++ b/etc/pazpar2.cfg @@ -7,7 +7,7 @@ - + diff --git a/src/config.c b/src/config.c index 2de8479..db50400 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.6 2007-01-08 19:39:12 quinn Exp $ */ +/* $Id: config.c,v 1.7 2007-01-09 18:06:28 quinn Exp $ */ #include @@ -91,7 +91,7 @@ static struct conf_service *parse_service(xmlNode *node) if (rank) md->rank = atoi(rank); else - md->rank = 1; + md->rank = 0; if (type) { @@ -107,7 +107,8 @@ static struct conf_service *parse_service(xmlNode *node) return 0; } } - md->type = Metadata_type_generic; + else + md->type = Metadata_type_generic; if (sortkey) { diff --git a/src/http_command.c b/src/http_command.c index bc1bee5..8f4b9b8 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.12 2007-01-08 19:41:56 quinn Exp $ + * $Id: http_command.c,v 1.13 2007-01-09 18:06:28 quinn Exp $ */ #include @@ -333,6 +333,11 @@ static void show_records(struct http_channel *c, int active) case Metadata_type_generic: wrbuf_puts(c->wrbuf, md->data.text); break; + case Metadata_type_year: + wrbuf_printf(c->wrbuf, "%d", md->data.year.year1); + if (md->data.year.year1 != md->data.year.year2) + wrbuf_printf(c->wrbuf, "-%d", md->data.year.year2); + break; default: wrbuf_puts(c->wrbuf, "[Can't represent]"); } diff --git a/src/pazpar2.c b/src/pazpar2.c index 17ce62f..8ee4ea9 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.20 2007-01-08 19:39:12 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.21 2007-01-09 18:06:28 quinn Exp $ */; #include #include @@ -424,6 +424,35 @@ static xmlDoc *normalize_record(struct client *cl, Z_External *rec) return rdoc; } +// Extract what appears to be years from buf, storing highest and +// lowest values. +static int extract_years(const char *buf, int *first, int *last) +{ + *first = -1; + *last = -1; + while (*buf) + { + const char *e; + int len; + + while (*buf && !isdigit(*buf)) + buf++; + len = 0; + for (e = buf; *e && isdigit(*e); e++) + len++; + if (len == 4) + { + int value = atoi(buf); + if (*first < 0 || value < *first) + *first = value; + if (*last < 0 || value > *last) + *last = value; + } + buf = e; + } + return *first; +} + static struct record *ingest_record(struct client *cl, Z_External *rec) { xmlDoc *xdoc = normalize_record(cl, rec); @@ -487,6 +516,7 @@ static struct record *ingest_record(struct client *cl, Z_External *rec) struct conf_metadata *md = 0; struct record_metadata **wheretoput, *newm; int imeta; + int first, last; // First, find out what field we're looking at for (imeta = 0; imeta < service->num_metadata; imeta++) @@ -514,11 +544,21 @@ static struct record *ingest_record(struct client *cl, Z_External *rec) { newm->data.text = nmem_strdup(se->nmem, value); } + else if (md->type == Metadata_type_year) + { + if (extract_years(value, &first, &last) < 0) + continue; + } else { yaz_log(YLOG_WARN, "Unknown type in metadata element %s", type); continue; } + if (md->type == Metadata_type_year && md->merge != Metadata_merge_range) + { + yaz_log(YLOG_WARN, "Only range merging supported for years"); + continue; + } if (md->merge == Metadata_merge_unique) { struct record_metadata *mnode; @@ -542,6 +582,23 @@ static struct record *ingest_record(struct client *cl, Z_External *rec) newm->next = *wheretoput; *wheretoput = newm; } + else if (md->merge == Metadata_merge_range) + { + assert(md->type == Metadata_type_year); + if (!*wheretoput) + { + *wheretoput = newm; + (*wheretoput)->data.year.year1 = first; + (*wheretoput)->data.year.year2 = last; + } + else + { + if (first < (*wheretoput)->data.year.year1) + (*wheretoput)->data.year.year1 = first; + if (last > (*wheretoput)->data.year.year2) + (*wheretoput)->data.year.year2 = last; + } + } else yaz_log(YLOG_WARN, "Don't know how to merge on element name %s", md->name);