From eed30a5461c8c61a88582b69af6ff735839646b4 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Wed, 31 Oct 2007 05:29:08 +0000 Subject: [PATCH] Added 'date' element type accepting YYYYMMDD --- src/config.c | 12 +++++------- src/config.h | 5 +++-- src/logic.c | 13 +++++++++---- src/normalize7bit.c | 9 ++++++--- src/normalize7bit.h | 4 ++-- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/config.c b/src/config.c index 359738f..c43109c 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.41 2007-09-10 16:25:50 adam Exp $ +/* $Id: config.c,v 1.42 2007-10-31 05:29:08 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -19,7 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: config.c,v 1.41 2007-09-10 16:25:50 adam Exp $ */ +/* $Id: config.c,v 1.42 2007-10-31 05:29:08 quinn Exp $ */ #include @@ -63,11 +63,7 @@ struct conf_metadata * conf_metadata_assign(NMEM nmem, metadata->name = nmem_strdup(nmem, name); - // enforcing that merge_range is always type_year - if (merge == Metadata_merge_range) - metadata->type = Metadata_type_year; - else - metadata->type = type; + metadata->type = type; // enforcing that type_year is always range_merge if (metadata->type == Metadata_type_year) @@ -299,6 +295,8 @@ static struct conf_service *parse_service(xmlNode *node) type = Metadata_type_generic; else if (!strcmp((const char *) xml_type, "year")) type = Metadata_type_year; + else if (!strcmp((const char *) xml_type, "date")) + type = Metadata_type_date; else { yaz_log(YLOG_FATAL, diff --git a/src/config.h b/src/config.h index 744cfb1..c03b459 100644 --- a/src/config.h +++ b/src/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.27 2007-09-10 16:25:50 adam Exp $ +/* $Id: config.h,v 1.28 2007-10-31 05:29:08 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -32,7 +32,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA enum conf_metadata_type { Metadata_type_generic, // Generic text field Metadata_type_number, // A number - Metadata_type_year // A number + Metadata_type_year, // A number + Metadata_type_date // A number }; enum conf_metadata_merge { diff --git a/src/logic.c b/src/logic.c index 625adc0..f6bf980 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.69 2007-10-02 12:11:14 adam Exp $ +/* $Id: logic.c,v 1.70 2007-10-31 05:29:08 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -1075,11 +1075,16 @@ static struct record_metadata *record_metadata_init( rec_md->data.text.disp = nmem_strdup(nmem, p); rec_md->data.text.sort = 0; } - else if (type == Metadata_type_year) + else if (type == Metadata_type_year || type == Metadata_type_date) { int first, last; - if (extract7bit_years((char *) value, &first, &last) < 0) + int longdate = 0; + + if (type == Metadata_type_date) + longdate = 1; + if (extract7bit_dates((char *) value, &first, &last, longdate) < 0) return 0; + rec_md->data.number.min = first; rec_md->data.number.max = last; } @@ -1252,7 +1257,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, sizeof(union data_types)); prt = pp2_relevance_tokenize( - global_parameters.server->sort_pct, + i global_parameters.server->sort_pct, rec_md->data.text.disp); pp2_relevance_token_next(prt); diff --git a/src/normalize7bit.c b/src/normalize7bit.c index a383b36..d5464e6 100644 --- a/src/normalize7bit.c +++ b/src/normalize7bit.c @@ -1,4 +1,4 @@ -/* $Id: normalize7bit.c,v 1.4 2007-09-07 10:46:33 adam Exp $ +/* $Id: normalize7bit.c,v 1.5 2007-10-31 05:29:08 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -91,7 +91,8 @@ char * normalize7bit_mergekey(char *buf, int skiparticle) // Extract what appears to be years from buf, storing highest and // lowest values. -int extract7bit_years(const char *buf, int *first, int *last) +// longdate==1, look for YYYYMMDD, longdate=0 look only for YYYY +int extract7bit_dates(const char *buf, int *first, int *last, int longdate) { *first = -1; *last = -1; @@ -105,9 +106,11 @@ int extract7bit_years(const char *buf, int *first, int *last) len = 0; for (e = buf; *e && isdigit(*e); e++) len++; - if (len == 4) + if ((len == 4 && !longdate) || (longdate && len >= 4 && len <= 8)) { int value = atoi(buf); + if (longdate && len == 4) + value *= 10000; // should really suffix 0101? if (*first < 0 || value < *first) *first = value; if (*last < 0 || value > *last) diff --git a/src/normalize7bit.h b/src/normalize7bit.h index b04638d..4318afa 100644 --- a/src/normalize7bit.h +++ b/src/normalize7bit.h @@ -1,4 +1,4 @@ -/* $Id: normalize7bit.h,v 1.2 2007-04-27 12:17:04 marc Exp $ +/* $Id: normalize7bit.h,v 1.3 2007-10-31 05:29:08 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA char *normalize7bit_mergekey(char *buf, int skiparticle); char * normalize7bit_generic(char * str, const char * rm_chars); -int extract7bit_years(const char *buf, int *first, int *last); +int extract7bit_dates(const char *buf, int *first, int *last, int longdate); #endif -- 1.7.10.4