From aecf31f5f3b2c09c07061dda3476cd724e369ccc Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Mon, 27 Jul 2015 15:34:56 +0200 Subject: [PATCH] PAZ-1013: Do not re-search if facet-id mapping not found --- src/client.c | 20 +++++++++++++++----- src/session.c | 15 +++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index 6e84061..5ebc11c 100644 --- a/src/client.c +++ b/src/client.c @@ -1387,11 +1387,21 @@ static int apply_limit(struct client *cl, const char *id = session_lookup_id_facet(cl->session, cl, name, values[i]); - if (id) { - values[i] = nmem_strdup(nmem_tmp, id); - yaz_log(YLOG_DEBUG, - "apply_limit: s='%s' found id '%s'",s->name,id ); - + if (id) + { + if ( *id ) + { + values[i] = nmem_strdup(nmem_tmp, id); + yaz_log(YLOG_DEBUG, + "apply_limit: s='%s' found id '%s'",s->name,id ); + } + else + { + yaz_log(YLOG_DEBUG, + "apply_limit: %s: term '%s' not found, failing client", + s->name, values[i] ); + ret = -1; + } } } nmem_strsplit_escape2(nmem_tmp, ",", s->value, &cvalues, diff --git a/src/session.c b/src/session.c index b4ecc62..8b4e101 100644 --- a/src/session.c +++ b/src/session.c @@ -228,20 +228,27 @@ static void session_add_id_facet(struct session *s, struct client *cl, } +// Look up a facet term, and return matching id +// If facet type not found, returns 0 +// If facet type found, but no matching term, returns "" const char *session_lookup_id_facet(struct session *s, struct client *cl, const char *type, const char *term) { + char *retval = 0; struct facet_id *t = s->facet_id_list; for (; t; t = t->next) { - if (!strcmp(client_get_id(cl), t->client_id) && - !strcmp(t->type, type) && !strcmp(t->term, term)) + if (!strcmp(client_get_id(cl), t->client_id) && !strcmp(t->type, type) ) { - return t->id; + retval = ""; + if ( !strcmp(t->term, term)) + { + return t->id; + } } } - return 0; + return retval; } void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl) -- 1.7.10.4