Implemented numeric sorting (sort by year). Bug #820.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 23 Jul 2007 12:23:30 +0000 (12:23 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 23 Jul 2007 12:23:30 +0000 (12:23 +0000)
src/reclists.c
test/test_http_10.res [new file with mode: 0644]
test/test_http_11.res [new file with mode: 0644]
test/test_http_urls

index ec591b1..783025f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: reclists.c,v 1.19 2007-07-16 17:01:46 adam Exp $
+/* $Id: reclists.c,v 1.20 2007-07-23 12:23:30 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -169,10 +169,12 @@ static int reclist_cmp(const void *p1, const void *p2)
     struct record_cluster *r1 = (*(struct record_cluster**) p1);
     struct record_cluster *r2 = (*(struct record_cluster**) p2);
     struct reclist_sortparms *s;
+    int res = 0;
 
-    for (s = sortparms; s; s = s->next)
+    for (s = sortparms; s && res == 0; s = s->next)
     {
-        int res;
+        union data_types *ut1 = r1->sortkeys[s->offset];
+        union data_types *ut2 = r2->sortkeys[s->offset];
         switch (s->type)
         {
             char *s1, *s2;
@@ -181,25 +183,36 @@ static int reclist_cmp(const void *p1, const void *p2)
                 res = r2->relevance - r1->relevance;
                 break;
             case Metadata_sortkey_string:
-                s1 = r1->sortkeys[s->offset] ? r1->sortkeys[s->offset]->text : "";
-                s2 = r2->sortkeys[s->offset] ? r2->sortkeys[s->offset]->text : "";
+                s1 = ut1 ? ut1->text : "";
+                s2 = ut2 ? ut2->text : "";
                 res = strcmp(s2, s1);
+                if (res)
+                {
+                    if (s->increasing)
+                        res *= -1;
+                }
                 break;
             case Metadata_sortkey_numeric:
-                res = 0;
+                if (ut1 && ut2)
+                {
+                    if (s->increasing)
+                        res = ut1->number.min  - ut2->number.min;
+                    else
+                        res = ut2->number.max  - ut1->number.max;
+                }
+                else if (ut1 && !ut2)
+                    res = -1;
+                else if (!ut1 && ut2)
+                    res = 1;
+                else
+                    res = 0;
                 break;
             default:
                 yaz_log(YLOG_FATAL, "Bad sort type: %d", s->type);
                 exit(1);
         }
-        if (res)
-        {
-            if (s->increasing)
-                res *= -1;
-            return res;
-        }
     }
-    return 0;
+    return res;
 }
 
 void reclist_sort(struct reclist *l, struct reclist_sortparms *parms)
diff --git a/test/test_http_10.res b/test/test_http_10.res
new file mode 100644 (file)
index 0000000..53779f4
--- /dev/null
@@ -0,0 +1,78 @@
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>9</merged>
+<total>10</total>
+<start>0</start>
+<num>9</num>
+<hit>
+
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the computer bible author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer science &amp; technology</md-title>
+<md-title-remainder>proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976</md-title-remainder>
+<md-date>1977</md-date><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title computer science technology author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+<hit>
+
+<md-title>The use of passwords for controlled access to computer resources</md-title>
+<md-date>1977</md-date>
+<md-author>Wood, Helen M</md-author><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the use of passwords for controlled access to computer resources author wood helen m medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer processing of dynamic images from an Anger scintillation camera</md-title>
+<md-title-remainder>the proceedings of a workshop</md-title-remainder>
+<md-date>1974</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title computer processing of dynamic images from an anger scintillation camera author medium book</recid>
+</hit>
+<hit>
+
+<md-title>The Puget Sound Region</md-title>
+<md-title-remainder>a portfolio of thematic computer maps</md-title-remainder>
+<md-date>1974</md-date>
+<md-author>Mairs, John W</md-author>
+<md-description>Scale of maps ca. 1:1,000,000</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the puget sound region author mairs john w medium book</recid>
+</hit>
+<hit>
+
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title a plan for community college computer development author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Washington metropolitan area rail computer feasibility study;</md-title>
+<md-title-remainder>final report</md-title-remainder>
+<md-date>1971</md-date>
+<md-author>Englund, Carl R</md-author>
+<md-description>&quot;Contract DOT-UT-10003.&quot;</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title washington metropolitan area rail computer feasibility study author englund carl r medium book</recid>
+</hit>
+<hit>
+
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<count>2</count>
+<recid>title how to program a computer author jack collins medium book</recid>
+</hit>
+</show>
diff --git a/test/test_http_11.res b/test/test_http_11.res
new file mode 100644 (file)
index 0000000..6a09703
--- /dev/null
@@ -0,0 +1,78 @@
+<show>
+<status>OK</status>
+<activeclients>0</activeclients>
+<merged>9</merged>
+<total>10</total>
+<start>0</start>
+<num>9</num>
+<hit>
+
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title a plan for community college computer development author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Washington metropolitan area rail computer feasibility study;</md-title>
+<md-title-remainder>final report</md-title-remainder>
+<md-date>1971</md-date>
+<md-author>Englund, Carl R</md-author>
+<md-description>&quot;Contract DOT-UT-10003.&quot;</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title washington metropolitan area rail computer feasibility study author englund carl r medium book</recid>
+</hit>
+<hit>
+
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the computer bible author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer processing of dynamic images from an Anger scintillation camera</md-title>
+<md-title-remainder>the proceedings of a workshop</md-title-remainder>
+<md-date>1974</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title computer processing of dynamic images from an anger scintillation camera author medium book</recid>
+</hit>
+<hit>
+
+<md-title>The Puget Sound Region</md-title>
+<md-title-remainder>a portfolio of thematic computer maps</md-title-remainder>
+<md-date>1974</md-date>
+<md-author>Mairs, John W</md-author>
+<md-description>Scale of maps ca. 1:1,000,000</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the puget sound region author mairs john w medium book</recid>
+</hit>
+<hit>
+
+<md-title>Computer science &amp; technology</md-title>
+<md-title-remainder>proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976</md-title-remainder>
+<md-date>1977</md-date><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title computer science technology author medium book</recid>
+</hit>
+<hit>
+
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+<hit>
+
+<md-title>The use of passwords for controlled access to computer resources</md-title>
+<md-date>1977</md-date>
+<md-author>Wood, Helen M</md-author><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<recid>title the use of passwords for controlled access to computer resources author wood helen m medium book</recid>
+</hit>
+<hit>
+
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author><location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<location id="z3950.indexdata.com/marc" name="Local Test"></location>
+<count>2</count>
+<recid>title how to program a computer author jack collins medium book</recid>
+</hit>
+</show>
index 1cf477a..83c6e71 100644 (file)
@@ -8,3 +8,5 @@ http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+progra
 http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book&offset=0
 http://localhost:9763/search.pz2?session=1&command=show&start=0&number=1&sort=title:0
 http://localhost:9763/search.pz2?session=1&command=show&start=0&number=1&sort=title:1
+http://localhost:9763/search.pz2?session=1&command=show&start=0&number=1&sort=date:0
+http://localhost:9763/search.pz2?session=1&command=show&start=0&number=1&sort=date:1