pz:recordfilter form is name[=substring].
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Sep 2009 18:18:50 +0000 (20:18 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Sep 2009 18:18:50 +0000 (20:18 +0200)
pz:recordfilter is now of the form name[=substring]. A record is
included if metadata element is present and existing (substring
omitted) or includes substring (substring included).

src/logic.c
test/test_http_urls

index e243d58..a45a8c3 100644 (file)
@@ -1035,20 +1035,6 @@ 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
@@ -1078,21 +1064,22 @@ static int check_record_filter(xmlNode *root, struct session_database *sdb)
             xmlChar *type = xmlGetProp(n, (xmlChar *) "type");
             if (type)
             {
-                const char *s1 = s;
                 size_t len;
-                const char *value;
-                while ((s1 = str_tok_n(s1, ",", &value, &len)) != 0)
+                const char *eq = strchr(s, '=');
+                if (eq)
+                    len = eq - s;
+                else
+                    len = strlen(s);
+                if (len == strlen((const char *)type) &&
+                    !memcmp((const char *) type, s, len))
                 {
-                    if (len == strlen((const char *)type) &&
-                        !memcmp((const char *) type, s, len))
+                    xmlChar *value = xmlNodeGetContent(n);
+                    if (value && *value)
                     {
-                        xmlChar *value = xmlNodeGetContent(n);
-                        if (value && *value)
-                        {
-                            xmlFree(value);
+                        if (!eq || strstr((const char *) value, eq+1))
                             match = 1;
-                        }
                     }
+                    xmlFree(value);
                 }
                 xmlFree(type);
             }
index c84e9b9..47adc23 100644 (file)
@@ -37,6 +37,7 @@ 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,title
+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=search&query=computer
+2
 http://localhost:9763/search.pz2?session=5&command=show&start=0&number=1&block=1