From 9bf6cd2cfa9d558b77fef6cc320964d7e7f5fc6e Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Sat, 23 Oct 2010 02:55:54 +0000 Subject: [PATCH] Added exact match record filter --- NEWS | 2 ++ doc/pazpar2_conf.xml | 7 ++++--- src/session.c | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 48123cb..d50e6a0 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +Added exact-match recordfilter; format name=value + --- 1.5.0 2010/10/05 SOLR support. Pazpar2 may operate as web service client for SOLR. diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index f91a4e0..1eb6fde 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -1055,10 +1055,11 @@ Specifies a filter which allows Pazpar2 to only include records that meet a certain criteria in a result. Unmatched records - will be ignored. The filter takes the form name[~value] , which + will be ignored. The filter takes the form name, name~value, or name=value, which will include only records with metadata element (name) that has the - substring (value) given. If value is omitted all records with the - metadata present will be included. + substring (~value) given, or matches exactly (=value). If value is omitted all records + with the named + metadata element present will be included. diff --git a/src/session.c b/src/session.c index 4d64e32..76364aa 100644 --- a/src/session.c +++ b/src/session.c @@ -1125,9 +1125,15 @@ static int check_record_filter(xmlNode *root, struct session_database *sdb) if (type) { size_t len; - const char *eq = strchr(s, '~'); - if (eq) - len = eq - s; + int substring; + const char *eq; + + if ((eq = strchr(s, '='))) + substring = 0; + else if ((eq = strchr(s, '~'))) + substring = 1; + if (eq) + len = eq - s; else len = strlen(s); if (len == strlen((const char *)type) && @@ -1136,7 +1142,9 @@ static int check_record_filter(xmlNode *root, struct session_database *sdb) xmlChar *value = xmlNodeGetContent(n); if (value && *value) { - if (!eq || strstr((const char *) value, eq+1)) + if (!eq || + (substring && strstr((const char *) value, eq+1)) || + (!substring && !strcmp((const char *) value, eq + 1))) match = 1; } xmlFree(value); -- 1.7.10.4