From aa2eabaa0f302aa987a3ec48ab57e06c4ce7e0f1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 14 Nov 2017 15:55:55 +0100 Subject: [PATCH 1/2] Union of filter keys + values PAZ-1050 --- src/database.c | 26 +++++++++++++++++++++----- test/test_filter.urls | 3 ++- test/test_filter_18.res | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test/test_filter_18.res diff --git a/src/database.c b/src/database.c index b063c6e1..9ee750c6 100644 --- a/src/database.c +++ b/src/database.c @@ -47,6 +47,7 @@ struct database_criterion_value { }; struct database_criterion { + int union_filter; char *name; enum pazpar2_database_criterion_type type; struct database_criterion_value *values; @@ -190,9 +191,15 @@ static struct database_criterion *create_database_criterion(NMEM m, char **values; int num; int i; + int union_filter = 0; if (!buf || !*buf) return 0; + if (*buf == '|') + { + union_filter = 1; + buf++; + } nmem_strsplit(m, ",", buf, &values, &num); for (i = 0; i < num; i++) { @@ -201,6 +208,8 @@ static struct database_criterion *create_database_criterion(NMEM m, int subi; struct database_criterion *new = nmem_malloc(m, sizeof(*new)); char *eq; + + new->union_filter = union_filter; for (eq = values[i]; *eq; eq++) if (*eq == '=') { @@ -240,13 +249,20 @@ static int database_match_criteria(struct setting **settings, struct conf_service *service, struct database_criterion *cl) { - for (; cl; cl = cl->next) - if (!match_criterion(settings, num_settings, service, cl)) - break; - if (cl) // one of the criteria failed to match -- skip this db + if (cl && cl->union_filter) + { + for (; cl; cl = cl->next) + if (match_criterion(settings, num_settings, service, cl)) + return 1; return 0; + } else - return 1; + { + for (; cl; cl = cl->next) + if (!match_criterion(settings, num_settings, service, cl)) + return 0; + } + return 1; } // Cycles through databases, calling a handler function on the ones for diff --git a/test/test_filter.urls b/test/test_filter.urls index fefe93b8..4a73be1b 100644 --- a/test/test_filter.urls +++ b/test/test_filter.urls @@ -5,7 +5,7 @@ http://localhost:9763/search.pz2?session=1&command=termlist&name=author,date,sub http://localhost:9763/search.pz2?session=1&command=search&query=the%207&filter=pz%3Aid%3Dlocalhost%3A9999 http://localhost:9763/search.pz2?session=1&command=show&block=1 http://localhost:9763/search.pz2?session=1&command=termlist&name=author,date,subject,xtargets -http://localhost:9763/search.pz2?session=1&command=search&query=the%207&filter=pz%3Aid%3Dlocalhost%3A9999 +http://localhost:9763/search.pz2?session=1&command=search&query=the%207&filter=%7Cpz%3Aid%3Dlocalhost%3A9999,pz%3Aid%3Dunknown http://localhost:9763/search.pz2?session=1&command=show http://localhost:9763/search.pz2?session=1&command=termlist&name=author,date,subject,xtargets http://localhost:9763/search.pz2?session=1&command=search&query=the&filter=pz%3Aid%3Dz3950.indexdata.com%2Fmarc @@ -15,3 +15,4 @@ http://localhost:9763/search.pz2?command=init http://localhost:9763/search.pz2?session=2&command=search&query=the%2022&filter=pz%3Aid%3Dlocalhost%3A9999 http://localhost:9763/search.pz2?session=2&command=show&sort=title:0&block=1 http://localhost:9763/search.pz2?session=2&command=show&sort=title:0&block=1 +http://localhost:9763/search.pz2?session=2&command=search&query=the%2022&filter=%7Cpz%3Aid%3Dunknown diff --git a/test/test_filter_18.res b/test/test_filter_18.res new file mode 100644 index 00000000..d486aeb7 --- /dev/null +++ b/test/test_filter_18.res @@ -0,0 +1,2 @@ + + \ No newline at end of file From 3b0756a4549bf97c832b18a31927cb4b2fdd63de Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 14 Nov 2017 18:50:52 +0100 Subject: [PATCH 2/2] Update documentation WRT filter --- doc/pazpar2_protocol.xml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/pazpar2_protocol.xml b/doc/pazpar2_protocol.xml index ed65bc7d..7bb24246 100644 --- a/doc/pazpar2_protocol.xml +++ b/doc/pazpar2_protocol.xml @@ -218,15 +218,21 @@ search.pz?command=settings&session=2044502273&pz:allow[search.com:210/db1]=1 Limits the search to a given set of targets specified by the filter. The filter consists of a comma-separated list of setting+operator+args - pairs. The setting is a Pazpar2 setting + pairs all of which must be satisfied (matched) for Pazpar2 to + include the target. + The setting is a Pazpar2 setting (such as pz:id). The operator is either = (string match) or ~ (substring match). The args is a list of values separated - by | (or , one of the values). - The idea is that only targets with a setting matching one of - the values given will be included in the search. + by |. If either of these values match, the + key-value pair is matched. + + + For Pazpar2 1.13.0 the filter can be prefixed with vertical bar + (|) as first character. In this case, if any of the + key-value pairs matches, Pazpar2 includes the target.