Tuned mergekey normalization
[pazpar2-moved-to-github.git] / src / pazpar2.c
index 2222679..c24ec00 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.32 2007-01-15 16:56:51 quinn Exp $ */
+/* $Id: pazpar2.c,v 1.34 2007-01-15 20:01:53 quinn Exp $ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -319,7 +319,10 @@ char *normalize_mergekey(char *buf, int skiparticle)
             p++;
     }
     if (buf != pout)
-        *pout = '\0';
+        do {
+            *(pout--) = '\0';
+        }
+        while (pout > buf && *pout == ' ');
 
     return buf;
 }
@@ -512,6 +515,7 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
     mergekey_norm = nmem_strdup(se->nmem, (char*) mergekey);
     xmlFree(mergekey);
     normalize_mergekey(mergekey_norm, 0);
+    yaz_log(YLOG_LOG, "MK: '%s'", mergekey_norm);
 
     cluster = reclist_insert(se->reclist, res, mergekey_norm, &se->total_merged);
     if (!cluster)
@@ -569,7 +573,12 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
             newm->next = 0;
             if (md->type == Metadata_type_generic)
             {
+                char *p;
                 newm->data.text = nmem_strdup(se->nmem, value);
+                for (p = newm->data.text + strlen(newm->data.text) - 1;
+                        p > newm->data.text && strchr(" ,/.", *p); p--)
+                    *p = '\0';
+
             }
             else if (md->type == Metadata_type_year)
             {