Skip to content

Commit

Permalink
Union of filter keys + values PAZ-1050
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdickmeiss committed Nov 14, 2017
1 parent 19867b6 commit aa2eaba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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 == '=')
{
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/test_filter.urls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions test/test_filter_18.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<error code="8" msg="No targets"></error>

0 comments on commit aa2eaba

Please sign in to comment.