X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Freclists.c;h=c2b45e731b5df8754c32e13e0ec0a594a194b1bf;hb=a989048e5451df8a25201757ba09a4ae50fa6568;hp=99c9c8732260c3a0180fe51dbcbeea89d9b364e5;hpb=646158a86d80e5ef0221ef7d7ce2cfc6ba31eacc;p=pazpar2-moved-to-github.git diff --git a/src/reclists.c b/src/reclists.c index 99c9c87..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")) + if (type != Metadata_sortkey_position) { - type = Metadata_sortkey_relevance; - } - else if (!strcmp(parm, "position")) - { - type = Metadata_sortkey_position; - } - else - { - 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: @@ -314,6 +328,17 @@ struct record_cluster *reclist_insert(struct reclist *l, if (!strcmp(merge_key, (*p)->record->merge_key)) { struct record_cluster *existing = (*p)->record; + struct record *re = existing->records; + + for (; re; re = re->next) + { + if (re->client == record->client && + record_compare(record, re, service)) + { + yaz_mutex_leave(l->mutex); + return 0; + } + } record->next = existing->records; existing->records = record; cluster = existing;