From 22ae3398d1153b29cdba238f1a5f21e7b3cf35e3 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 19 Sep 2011 15:21:28 +0200 Subject: [PATCH] New special sort parameter value 'position'. The 'position' sorts merged records by their original position from the remote target. This is primarily useful for debugging and may be used for targets that already perform some kind of relevance ranking. Note that sort by default is decreasing; so to get records in their original order sort=position:1 must be used. --- doc/pazpar2_protocol.xml | 3 ++- src/pazpar2_config.h | 3 ++- src/reclists.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/doc/pazpar2_protocol.xml b/doc/pazpar2_protocol.xml index d332a62..fd10f67 100644 --- a/doc/pazpar2_protocol.xml +++ b/doc/pazpar2_protocol.xml @@ -344,7 +344,8 @@ search.pz2?session=2044502273&command=stat increasing or decreasing order according to that field. 0==Decreasing is the default. Sort field names can be any field name designated as a sort field - in the pazpar2.cfg file, or the special name 'relevance'. + in the pazpar2.cfg file, or the special names 'relevance' and + 'position'. diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 1906b85..c8ea60e 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -47,7 +47,8 @@ enum conf_sortkey_type { Metadata_sortkey_relevance, Metadata_sortkey_numeric, // Standard numerical sorting Metadata_sortkey_skiparticle, // Skip leading article when sorting - Metadata_sortkey_string // Flat string + Metadata_sortkey_string, // Flat string + Metadata_sortkey_position // Position }; // This controls the ability to insert 'static' values from settings into retrieval recs diff --git a/src/reclists.c b/src/reclists.c index 7025af1..b4e2a6d 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -85,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 { @@ -163,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; -- 1.7.10.4