From 8b9b24543393aabb69c0efb0ee9b1390ee9d22f2 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 28 Sep 2009 12:16:48 +0200 Subject: [PATCH] Comma separated value for pz:recordfilter. --- src/logic.c | 45 +++++++++++++++++++++++++++++++++------------ test/test_http_urls | 2 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/logic.c b/src/logic.c index 7f23b27..c76ba28 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1032,6 +1032,20 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no, return mergekey_norm; } +static const char *str_tok_n(const char *s, const char *delim, + const char **res, size_t *len) +{ + *res = s; + while (*s && !strchr(delim, *s)) + s++; + *len = s - *res; + if (*len == 0) + return 0; + if (*s && strchr(delim, *s)) + s++; + return s; +} + /** \brief see if metadata for pz:recordfilter exists \param root xml root element of normalized record \param sdb session database for client @@ -1059,19 +1073,26 @@ static int check_record_filter(xmlNode *root, struct session_database *sdb) if (!strcmp((const char *) n->name, "metadata")) { xmlChar *type = xmlGetProp(n, (xmlChar *) "type"); - - if (!type) - continue; - if (!strcmp((const char *) type, s)) + if (type) { - xmlChar *value = xmlNodeGetContent(n); - if (value && *value) + const char *s1 = s; + size_t len; + const char *value; + while ((s1 = str_tok_n(s1, ",", &value, &len)) != 0) { - xmlFree(value); - match = 1; + if (len == strlen((const char *)type) && + !memcmp((const char *) type, s, len)) + { + xmlChar *value = xmlNodeGetContent(n); + if (value && *value) + { + xmlFree(value); + match = 1; + } + } } + xmlFree(type); } - xmlFree(type); } } return match; @@ -1088,11 +1109,11 @@ struct record *ingest_record(struct client *cl, const char *rec, int record_no) { struct session_database *sdb = client_get_database(cl); - xmlDoc *xdoc = normalize_record(sdb, client_get_session(cl), rec); + struct session *se = client_get_session(cl); + xmlDoc *xdoc = normalize_record(sdb, se, rec); xmlNode *root, *n; struct record *record; struct record_cluster *cluster; - struct session *se = client_get_session(cl); const char *mergekey_norm; xmlChar *type = 0; xmlChar *value = 0; @@ -1128,7 +1149,7 @@ struct record *ingest_record(struct client *cl, const char *rec, &se->total_merged); if (global_parameters.dump_records) yaz_log(YLOG_LOG, "Cluster id %s from %s (#%d)", cluster->recid, - client_get_database(cl)->database->url, record_no); + sdb->database->url, record_no); if (!cluster) { /* no room for record */ diff --git a/test/test_http_urls b/test/test_http_urls index bc45cd1..c84e9b9 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -37,6 +37,6 @@ http://localhost:9763/search.pz2?session=4&command=search&query=computer 2 http://localhost:9763/search.pz2?session=4&command=show&start=0&number=1&block=1 http://localhost:9763/search.pz2?command=init&clear=1 -http://localhost:9763/search.pz2?session=5&command=settings&pz:name[z3950.indexdata.com%2Fmarc]=marc&pz:requestsyntax[z3950.indexdata.com%2Fmarc]=usmarc&pz:nativesyntax[z3950.indexdata.com%2Fmarc]=iso2709&pz:xslt[z3950.indexdata.com%2Fmarc]=marc21.xsl&pz:recordfilter[z3950.indexdata.com%2Fmarc]=date +http://localhost:9763/search.pz2?session=5&command=settings&pz:name[z3950.indexdata.com%2Fmarc]=marc&pz:requestsyntax[z3950.indexdata.com%2Fmarc]=usmarc&pz:nativesyntax[z3950.indexdata.com%2Fmarc]=iso2709&pz:xslt[z3950.indexdata.com%2Fmarc]=marc21.xsl&pz:recordfilter[z3950.indexdata.com%2Fmarc]=date,title http://localhost:9763/search.pz2?session=5&command=search&query=computer http://localhost:9763/search.pz2?session=5&command=show&start=0&number=1&block=1 -- 1.7.10.4