X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Freclists.c;h=c2b45e731b5df8754c32e13e0ec0a594a194b1bf;hb=6270643579b3496a2c51ef2c8abb0fb4b34726de;hp=6ac71cddbcff3fc6527584d49214d2ed162f2a94;hpb=b7a4225d4b5c5e2e375a659e1b7f46717bb3d039;p=pazpar2-moved-to-github.git diff --git a/src/reclists.c b/src/reclists.c index 6ac71cd..c2b45e7 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2011 Index Data + Copyright (C) 2006-2012 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 @@ -64,10 +64,10 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, char parm[256]; char *pp; const char *cpp; - int increasing; + int increasing = 0; int i; int offset = 0; - enum conf_sortkey_type type; + enum conf_sortkey_type type = Metadata_sortkey_string; struct reclist_sortparms *new; if (!(cpp = strchr(parms, ','))) @@ -77,39 +77,56 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, if ((pp = strchr(parm, ':'))) { - increasing = pp[1] == '1' ? 1 : 0; + if (pp[1] == '1') + increasing = 1; + else if (pp[1] == '0') + increasing = 0; + else + { + yaz_log(YLOG_FATAL, "Bad sortkey modifier: %s", parm); + return 0; + } + + if (pp[2]) + { + if (pp[2] == 'p') + type = Metadata_sortkey_position; + else + yaz_log(YLOG_FATAL, "Bad sortkey modifier: %s", parm); + } *pp = '\0'; } - else - increasing = 0; - if (!strcmp(parm, "relevance")) - { - type = Metadata_sortkey_relevance; - } - else if (!strcmp(parm, "position")) - { - type = Metadata_sortkey_position; - } - else + if (type != Metadata_sortkey_position) { - for (i = 0; i < service->num_sortkeys; i++) + if (!strcmp(parm, "relevance")) { - struct conf_sortkey *sk = &service->sortkeys[i]; - if (!strcmp(sk->name, parm)) - { - type = sk->type; - if (type == Metadata_sortkey_skiparticle) - type = Metadata_sortkey_string; - break; - } - } - if (i >= service->num_sortkeys) + type = Metadata_sortkey_relevance; + } + else if (!strcmp(parm, "position")) { - yaz_log(YLOG_FATAL, "Bad sortkey: %s", parm); - return 0; + type = Metadata_sortkey_position; } else + { + for (i = 0; i < service->num_sortkeys; i++) + { + struct conf_sortkey *sk = &service->sortkeys[i]; + if (!strcmp(sk->name, parm)) + { + type = sk->type; + if (type == Metadata_sortkey_skiparticle) + type = Metadata_sortkey_string; + break; + } + } + if (i >= service->num_sortkeys) + { + yaz_log(YLOG_FATAL, "Sortkey not defined in service: %s", + parm); + return 0; + } offset = i; + } } new = *rp = nmem_malloc(nmem, sizeof(struct reclist_sortparms)); new->next = 0; @@ -179,10 +196,7 @@ static int reclist_cmp(const void *p1, const void *p2) 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; + res = pos1 - pos2; } break; default: