Added date support (md-date in show command).
authorSebastian Hammer <quinn@indexdata.com>
Tue, 9 Jan 2007 18:06:28 +0000 (18:06 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Tue, 9 Jan 2007 18:06:28 +0000 (18:06 +0000)
etc/marc21.xsl
etc/pazpar2.cfg
src/config.c
src/http_command.c
src/pazpar2.c

index cd20702..344a6c5 100644 (file)
        <xsl:value-of select="marc:datafield[@tag='245']/marc:subfield[@code='b']"/>
       </pz:metadata>
 
-      <!--
       <xsl:for-each select="marc:datafield[@tag='260']">
         <pz:metadata type="date">
          <xsl:value-of select="marc:subfield[@code='c']"/>
        </pz:metadata>
       </xsl:for-each>
-      -->
 
       <xsl:for-each select="marc:datafield[@tag='650']">
        <pz:metadata type="subject">
index 6c14bc3..3ea7efa 100644 (file)
@@ -7,7 +7,7 @@
 
   <service>
     <metadata name="title" brief="yes" sortkey="skiparticle" merge="longest" rank="6"/>
-    <!-- <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"/> -->
+    <metadata name="date" brief="yes" sortkey="numeric" type="year" merge="range"/>
     <metadata name="author" brief="yes" termlist="yes" merge="longest" rank="2"/>
     <metadata name="subject" merge="unique" termlist="yes" rank="3"/>
   </service>
index 2de8479..db50400 100644 (file)
@@ -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 <string.h>
 
@@ -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)
             {
index bc1bee5..8f4b9b8 100644 (file)
@@ -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 <stdio.h>
@@ -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]");
                 }
index 17ce62f..8ee4ea9 100644 (file)
@@ -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 <stdlib.h>
 #include <stdio.h>
@@ -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);