X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Freclists.c;h=b4e2a6dc2ee77510e588008c219547b9c15b628d;hb=da186c5b5656cd210b2a8a8d9c75d2af0c8c3f66;hp=284d19c39beef11b28160210a22b917e82fb788a;hpb=5e525d47d446d0c02985f007ae0fb0905444e305;p=pazpar2-moved-to-github.git diff --git a/src/reclists.c b/src/reclists.c index 284d19c..b4e2a6d 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-2011 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,7 +25,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include -#include "pazpar2.h" +#include "ppmutex.h" +#include "session.h" #include "reclists.h" #include "jenkins_hash.h" @@ -84,6 +85,10 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, if (!strcmp(parm, "relevance")) { type = Metadata_sortkey_relevance; + } + else if (!strcmp(parm, "position")) + { + type = Metadata_sortkey_position; } else { @@ -162,6 +167,23 @@ 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; + if (s->increasing) + res = pos1 - pos2; + else + res = pos2 - pos1; + } + break; default: yaz_log(YLOG_WARN, "Bad sort type: %d", s->type); res = 0; @@ -249,13 +271,14 @@ struct reclist *reclist_create(NMEM nmem) res->num_records = 0; res->mutex = 0; - yaz_mutex_create(&res->mutex); + pazpar2_mutex_create(&res->mutex, "reclist"); return res; } void reclist_destroy(struct reclist *l) { - yaz_mutex_destroy(&l->mutex); + if (l) + yaz_mutex_destroy(&l->mutex); } int reclist_get_num_records(struct reclist *l) @@ -266,10 +289,10 @@ int reclist_get_num_records(struct reclist *l) } // Insert a record. Return record cluster (newly formed or pre-existing) -struct record_cluster *reclist_insert( struct reclist *l, - struct conf_service *service, - struct record *record, - char *merge_key, int *total) +struct record_cluster *reclist_insert(struct reclist *l, + struct conf_service *service, + struct record *record, + const char *merge_key, int *total) { unsigned int bucket; struct reclist_bucket **p; @@ -307,10 +330,10 @@ struct record_cluster *reclist_insert( struct reclist *l, new->record = cluster; new->hnext = 0; cluster->records = record; - cluster->merge_key = merge_key; + cluster->merge_key = nmem_strdup(l->nmem, merge_key); cluster->relevance_score = 0; cluster->term_frequency_vec = 0; - cluster->recid = merge_key; + cluster->recid = nmem_strdup(l->nmem, merge_key); (*total)++; cluster->metadata = nmem_malloc(l->nmem,