From: Adam Dickmeiss Date: Wed, 21 Sep 2011 12:48:49 +0000 (+0200) Subject: Make termlist sorting stable X-Git-Tag: v1.6.3~2 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=dd072ff41444dfdd49c76ecc3ca634b06cb75dd1;p=pazpar2-moved-to-github.git Make termlist sorting stable Terms with same frequency are now sorted by their display name. This makes a pretty display and improves our regression test because qsort is not a stable sort. --- diff --git a/src/termlists.c b/src/termlists.c index 9741eb2..0b870bb 100644 --- a/src/termlists.c +++ b/src/termlists.c @@ -147,8 +147,12 @@ void termlist_insert(struct termlist *tl, const char *display_term, static int compare(const void *s1, const void *s2) { - struct termlist_score **p1 = (struct termlist_score**) s1, **p2 = (struct termlist_score **) s2; - return (*p2)->frequency - (*p1)->frequency; + struct termlist_score **p1 = (struct termlist_score **) s1; + struct termlist_score **p2 = (struct termlist_score **) s2; + int d = (*p2)->frequency - (*p1)->frequency; + if (d) + return d; + return strcmp((*p1)->display_term, (*p2)->display_term); } struct termlist_score **termlist_highscore(struct termlist *tl, int *len) diff --git a/test/test_facets_24.res b/test/test_facets_24.res index a872155..8be225c 100644 --- a/test/test_facets_24.res +++ b/test/test_facets_24.res @@ -11,22 +11,22 @@ Jack Collins2 +Englund, Carl R1 Mairs, John W1 Wood, Helen M1 -Englund, Carl R1 -Radioisotope scanning1 -Scintillation cameras1 -Imaging systems in medicine1 -Bible. O.T1 Bible1 +Bible. O.T1 Cartography1 -Puget Sound region (Wash.)1 -Tomography1 -Optical pattern recognition1 Computers1 +Imaging systems in medicine1 +Optical pattern recognition1 +Puget Sound region (Wash.)1 +Radioisotope scanning1 Railroads1 +Scintillation cameras1 +Tomography1 date0100 diff --git a/test/test_facets_6.res b/test/test_facets_6.res index 8230a4b..8755ee8 100644 --- a/test/test_facets_6.res +++ b/test/test_facets_6.res @@ -14,21 +14,21 @@ Mairs, John W1 -Radioisotope scanning1 -Scintillation cameras1 -Imaging systems in medicine1 -Bible. O.T1 Bible1 +Bible. O.T1 Cartography1 +Imaging systems in medicine1 +Optical pattern recognition1 Puget Sound region (Wash.)1 +Radioisotope scanning1 +Scintillation cameras1 Tomography1 -Optical pattern recognition1 19742 19772 -19801 19731 +19801 diff --git a/test/test_icu_8.res b/test/test_icu_8.res index a200b10..b816997 100644 --- a/test/test_icu_8.res +++ b/test/test_icu_8.res @@ -2,20 +2,20 @@ 0 Jack Collins2 +Englund, Carl R.1 Mairs, John W.1 Wood, Helen M.1 -Englund, Carl R.1 -Radioisotope Scanning1 -Scintillation Cameras1 -Imaging Systems In Medicine1 Cartography1 -Tomography1 -Optical Pattern Recognition1 +Community Colleges1 Computers1 +Imaging Systems In Medicine1 +Optical Pattern Recognition1 +Radioisotope Scanning1 Railroads1 +Scintillation Cameras1 +Tomography1 Universities And Colleges1 -Community Colleges1 diff --git a/test/test_solr_5.res b/test/test_solr_5.res index a9ae3fd..dd89fec 100644 --- a/test/test_solr_5.res +++ b/test/test_solr_5.res @@ -17,48 +17,48 @@ Water quality management11 Water conservation9 Drinking water7 -Water use6 Water rights6 +Water use6 Groundwater4 Hydrology3 -Water supply3 +Nutrient pollution of water3 +Purification of3 Rural3 -Water-supply engineering3 Water harvesting3 Baker, M. N2 -Hochschwender, Ted1 +Ambrose, David1 +Bauer, Steve1 +Bryan, Michelle1 Davis, Floyd1 De Villiers, Marq1 -Majeed, Abdul1 +Dibdin, William Joseph1 +Faeth, Paul1 +Farnham, Henry P1 Fisher, D. E1 -Thresh, John Clough1 -Glover, David1 Frey, Hans1 -Ravi, Rājeśa1 -Sherk, George William1 -Faeth, Paul1 -Bryan, Michelle1 -Powell, J. M1 -Shade, Patricia J1 +Gingerich, Stephen B1 +Glover, David1 +Grant, Pamela1 +Hochschwender, Ted1 200032 199929 19986 19974 -20013 19963 +20013 +18962 18972 18982 18992 19032 -18962 -18911 -19011 +18351 +18391 +18481 18551 -19041 book99