Preserve order for merged metadata
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Sep 2011 20:32:08 +0000 (22:32 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Sep 2011 20:32:08 +0000 (22:32 +0200)
Fixes issue mentioned by Sven Porst
http://lists.indexdata.dk/pipermail/yazlist/2011-July/003230.html

src/session.c
test/test_http_23.res
test/test_http_6.res

index fa9ebb3..d56b396 100644 (file)
@@ -1453,16 +1453,15 @@ static int ingest_to_cluster(struct client *cl,
             // assign cluster or record based on merge action
             if (ser_md->merge == Metadata_merge_unique)
             {
-                struct record_metadata *mnode;
-                for (mnode = *wheretoput; mnode; mnode = mnode->next)
-                    if (!strcmp((const char *) mnode->data.text.disp, 
+                while (*wheretoput)
+                {
+                    if (!strcmp((const char *) (*wheretoput)->data.text.disp, 
                                 rec_md->data.text.disp))
                         break;
-                if (!mnode)
-                {
-                    rec_md->next = *wheretoput;
-                    *wheretoput = rec_md;
+                    wheretoput = &(*wheretoput)->next;
                 }
+                if (!*wheretoput)
+                    *wheretoput = rec_md;
             }
             else if (ser_md->merge == Metadata_merge_longest)
             {
@@ -1507,7 +1506,8 @@ static int ingest_to_cluster(struct client *cl,
             }
             else if (ser_md->merge == Metadata_merge_all)
             {
-                rec_md->next = *wheretoput;
+                while (*wheretoput)
+                    wheretoput = &(*wheretoput)->next;
                 *wheretoput = rec_md;
             }
             else if (ser_md->merge == Metadata_merge_range)
index c248dbb..a3476cd 100644 (file)
@@ -6,8 +6,8 @@
 
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
-<md-lccn>11224467</md-lccn>
-<md-lccn>11224466</md-lccn><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-lccn>11224466</md-lccn>
+<md-lccn>11224467</md-lccn><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
 <md-id>11224467</md-id>
index c0c00f3..f079915 100644 (file)
@@ -6,8 +6,8 @@
 
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
-<md-lccn>11224467</md-lccn>
-<md-lccn>11224466</md-lccn><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-lccn>11224466</md-lccn>
+<md-lccn>11224467</md-lccn><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
 <md-id>11224467</md-id>