X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Freclists.c;h=201dab6d34d11c970462f4960d2d0d025b84eed3;hb=824eea389688f854677efd0231182a893d00f8f4;hp=7025af1b20b96aa183e83987e0f27424681da257;hpb=6ff7cb53029747ad6ac60fde903630ea063b5218;p=pazpar2-moved-to-github.git diff --git a/src/reclists.c b/src/reclists.c index 7025af1..201dab6 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,41 +77,63 @@ 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 - { - 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; new->offset = offset; new->type = type; new->increasing = increasing; + new->name = nmem_strdup(nmem, parm); rp = &new->next; if (*(parms = cpp)) parms++; @@ -163,9 +185,24 @@ static int reclist_cmp(const void *p1, const void *p2) else res = 0; break; + case Metadata_sortkey_position: + if (r1->records && r2->records) + { + int pos1 = 0, pos2 = 0; + struct record *rec; + for (rec = r1->records; rec; rec = rec->next) + if (pos1 == 0 || rec->position < pos1) + pos1 = rec->position; + for (rec = r2->records; rec; rec = rec->next) + if (pos2 == 0 || rec->position < pos2) + pos2 = rec->position; + res = pos1 - pos2; + } + break; default: yaz_log(YLOG_WARN, "Bad sort type: %d", s->type); res = 0; + break; } } if (res == 0) @@ -292,6 +329,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;