From 9e625af75632d86876dc419d0140e51bdef98d7e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 23 Jul 2007 12:23:30 +0000 Subject: [PATCH] Implemented numeric sorting (sort by year). Bug #820. --- src/reclists.c | 39 ++++++++++++++++--------- test/test_http_10.res | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_http_11.res | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_http_urls | 2 ++ 4 files changed, 184 insertions(+), 13 deletions(-) create mode 100644 test/test_http_10.res create mode 100644 test/test_http_11.res diff --git a/src/reclists.c b/src/reclists.c index ec591b1..783025f 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -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 index 0000000..53779f4 --- /dev/null +++ b/test/test_http_10.res @@ -0,0 +1,78 @@ + +OK +0 +9 +10 +0 +9 + + +The Computer Bible +1973-1980 +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +title the computer bible author medium book + + + +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +title computer science technology author medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + + +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +title computer processing of dynamic images from an anger scintillation camera author medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +title the puget sound region author mairs john w medium book + + + +A plan for community college computer development +1971 +Cover title +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +title washington metropolitan area rail computer feasibility study author englund carl r medium book + + + +How to program a computer +Jack Collins + +2 +title how to program a computer author jack collins medium book + + diff --git a/test/test_http_11.res b/test/test_http_11.res new file mode 100644 index 0000000..6a09703 --- /dev/null +++ b/test/test_http_11.res @@ -0,0 +1,78 @@ + +OK +0 +9 +10 +0 +9 + + +A plan for community college computer development +1971 +Cover title +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +title washington metropolitan area rail computer feasibility study author englund carl r medium book + + + +The Computer Bible +1973-1980 +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +title the computer bible author medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +title computer processing of dynamic images from an anger scintillation camera author medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +title the puget sound region author mairs john w medium book + + + +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +title computer science technology author medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + + +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +How to program a computer +Jack Collins + +2 +title how to program a computer author jack collins medium book + + diff --git a/test/test_http_urls b/test/test_http_urls index 1cf477a..83c6e71 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -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 -- 1.7.10.4