X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Freclists.c;h=c2b45e731b5df8754c32e13e0ec0a594a194b1bf;hb=07bc8f15f98e22a866adda001ada9010567b3429;hp=1221b2b588b8d66bac6635351f0d27ef389f500e;hpb=b73890ede1ee6eeb8a07937733871077df6f15b9;p=pazpar2-moved-to-github.git diff --git a/src/reclists.c b/src/reclists.c index 1221b2b..c2b45e7 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2010 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 @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include +#include "ppmutex.h" #include "session.h" #include "reclists.h" #include "jenkins_hash.h" @@ -63,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, ','))) @@ -76,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++; @@ -162,6 +185,20 @@ 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; @@ -249,8 +286,7 @@ struct reclist *reclist_create(NMEM nmem) res->num_records = 0; res->mutex = 0; - yaz_mutex_create(&res->mutex); - yaz_mutex_set_name(res->mutex, "reclist"); + pazpar2_mutex_create(&res->mutex, "reclist"); return res; } @@ -292,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;