Rename client_get_url to client_get_id
[pazpar2-moved-to-github.git] / src / reclists.c
index 1221b2b..b4e2a6d 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2010 Index Data
+   Copyright (C) 2006-2011 Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <yaz/yaz-util.h>
 
+#include "ppmutex.h"
 #include "session.h"
 #include "reclists.h"
 #include "jenkins_hash.h"
@@ -84,6 +85,10 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms,
         if (!strcmp(parm, "relevance"))
         {
             type = Metadata_sortkey_relevance;
+        } 
+        else if (!strcmp(parm, "position"))
+        {
+            type = Metadata_sortkey_position;
         }
         else
         {
@@ -162,6 +167,23 @@ static int reclist_cmp(const void *p1, const void *p2)
             else
                 res = 0;
             break;
+        case Metadata_sortkey_position:
+            if (r1->records && r2->records)
+            {
+                int pos1 = 0, pos2 = 0;
+                struct record *rec;
+                for (rec = r1->records; rec; rec = rec->next)
+                    if (pos1 == 0 || rec->position < pos1)
+                        pos1 = rec->position;
+                for (rec = r2->records; rec; rec = rec->next)
+                    if (pos2 == 0 || rec->position < pos2)
+                        pos2 = rec->position;
+                if (s->increasing)
+                    res = pos1 - pos2;
+                else
+                    res = pos2 - pos1;
+            }
+            break;
         default:
             yaz_log(YLOG_WARN, "Bad sort type: %d", s->type);
             res = 0;
@@ -249,8 +271,7 @@ struct reclist *reclist_create(NMEM nmem)
 
     res->num_records = 0;
     res->mutex = 0;
-    yaz_mutex_create(&res->mutex);
-    yaz_mutex_set_name(res->mutex, "reclist");
+    pazpar2_mutex_create(&res->mutex, "reclist");
     return res;
 }