From a8646d6b1909bcc5497bcc8471743b80a792db36 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 22 Nov 2013 11:32:20 +0100 Subject: [PATCH] New ranking type relevance_h --- src/pazpar2_config.c | 3 +++ src/pazpar2_config.h | 5 ++++- src/reclists.c | 7 +++++++ src/relevance.c | 6 +++++- src/relevance.h | 3 ++- src/session.c | 5 +++-- test/test_url.urls | 4 ++-- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 8068b13..b11148d 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -1017,6 +1017,9 @@ static void info_service_metadata(struct conf_service *service, WRBUF w) case Metadata_sortkey_relevance: wrbuf_puts(w, "relevance"); break; + case Metadata_sortkey_relevance_h: + wrbuf_puts(w, "relevance_h"); + break; case Metadata_sortkey_numeric: wrbuf_puts(w, "numeric"); break; diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index ee195b9..6cf7cb2 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -20,8 +20,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef PAZPAR2_CONFIG_H #define PAZPAR2_CONFIG_H -#include "normalize_cache.h" +#include +#include +#include "normalize_cache.h" #include #include #include @@ -47,6 +49,7 @@ enum conf_metadata_merge { enum conf_sortkey_type { Metadata_sortkey_relevance, + Metadata_sortkey_relevance_h, // Heikki's ranking Metadata_sortkey_numeric, // Standard numerical sorting Metadata_sortkey_skiparticle, // Skip leading article when sorting Metadata_sortkey_string, // Flat string diff --git a/src/reclists.c b/src/reclists.c index b16a60e..bec6268 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -101,6 +101,10 @@ struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, { type = Metadata_sortkey_relevance; } + else if (!strcmp(parm, "relevance_h")) + { + type = Metadata_sortkey_relevance_h; + } else if (!strcmp(parm, "position")) { type = Metadata_sortkey_position; @@ -159,6 +163,9 @@ static int reclist_cmp(const void *p1, const void *p2) case Metadata_sortkey_relevance: res = r2->relevance_score - r1->relevance_score; break; + case Metadata_sortkey_relevance_h: + res = r2->relevance_score - r1->relevance_score; + break; case Metadata_sortkey_string: s1 = ut1 ? ut1->text.sort : ""; s2 = ut2 ? ut2->text.sort : ""; diff --git a/src/relevance.c b/src/relevance.c index 08527ae..2fd7414 100644 --- a/src/relevance.c +++ b/src/relevance.c @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include "pazpar2_config.h" #include "relevance.h" #include "session.h" @@ -352,7 +353,8 @@ void relevance_donerecord(struct relevance *r, struct record_cluster *cluster) } // Prepare for a relevance-sorted read -void relevance_prepare_read(struct relevance *rel, struct reclist *reclist) +void relevance_prepare_read(struct relevance *rel, struct reclist *reclist, + enum conf_sortkey_type type) { int i; float *idfvec = xmalloc(rel->vec_len * sizeof(float)); @@ -412,6 +414,8 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist) { wrbuf_printf(w, "score = relevance(%d);\n", relevance); } + if (0 && type == Metadata_sortkey_relevance_h) + relevance *= 2; rec->relevance_score = relevance; } reclist_leave(reclist); diff --git a/src/relevance.h b/src/relevance.h index 76bbc22..1a6f398 100644 --- a/src/relevance.h +++ b/src/relevance.h @@ -44,7 +44,8 @@ int relevance_snippet(struct relevance *r, void relevance_donerecord(struct relevance *r, struct record_cluster *cluster); -void relevance_prepare_read(struct relevance *rel, struct reclist *rec); +void relevance_prepare_read(struct relevance *rel, struct reclist *rec, + enum conf_sortkey_type type); #endif diff --git a/src/session.c b/src/session.c index 9091b6b..f07bfcb 100644 --- a/src/session.c +++ b/src/session.c @@ -1314,9 +1314,10 @@ struct record_cluster **show_range_start(struct session *se, if (se->relevance) { for (spp = sp; spp; spp = spp->next) - if (spp->type == Metadata_sortkey_relevance) + if (spp->type == Metadata_sortkey_relevance + || spp->type == Metadata_sortkey_relevance_h) { - relevance_prepare_read(se->relevance, se->reclist); + relevance_prepare_read(se->relevance, se->reclist, spp->type); break; } for (l = se->clients_active; l; l = l->next) { diff --git a/test/test_url.urls b/test/test_url.urls index 6694fe6..045a7c8 100644 --- a/test/test_url.urls +++ b/test/test_url.urls @@ -17,7 +17,7 @@ http://localhost:9763/search.pz2?session=1&command=search&query=water 2 http://localhost:9763/search.pz2?session=1&command=show&block=1&sort=title:1p 2 http://localhost:9763/search.pz2?session=1&command=show&block=1&sort=date:0p http://localhost:9763/search.pz2?session=1&command=service -http://localhost:9763/search.pz2?session=1&command=show&sort=relevance +http://localhost:9763/search.pz2?session=1&command=show&sort=relevance_h http://localhost:9763/search.pz2?session=1&command=record&id=content%3A+title+coal+sample+bank+author+medium+book http://localhost:9763/search.pz2?session=1&command=show&block=1&sort=title:1 -http://localhost:9763/search.pz2?session=1&command=record&id=content%3A+title+coal+sample+bank+author+medium+book \ No newline at end of file +http://localhost:9763/search.pz2?session=1&command=record&id=content%3A+title+coal+sample+bank+author+medium+book -- 1.7.10.4