From: Sebastian Hammer Date: Fri, 23 Mar 2007 03:26:22 +0000 (+0000) Subject: Added support for multiple values in filter statement -- separated by |, eg X-Git-Tag: stable.27032007~7 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=56d94019bbdff3b9823069b61f0f0ec6a671f923;p=pazpar2-moved-to-github.git Added support for multiple values in filter statement -- separated by |, eg filter=id=target1|target2|target3 --- diff --git a/src/database.c b/src/database.c index 9cb2406..5ee51bb 100644 --- a/src/database.c +++ b/src/database.c @@ -1,4 +1,4 @@ -/* $Id: database.c,v 1.3 2007-03-20 05:32:58 quinn Exp $ */ +/* $Id: database.c,v 1.4 2007-03-23 03:26:22 quinn Exp $ */ #include #include @@ -185,10 +185,17 @@ struct database *find_database(const char *id, int new) return load_database(id); } +// This will be generalized at some point static int match_criterion(struct database *db, struct database_criterion *c) { if (!strcmp(c->name, "id")) - return (!strcmp(c->value, db->url)); + { + struct database_criterion_value *v; + for (v = c->values; v; v = v->next) + if (!strcmp(v->value, db->url)) + return 1; + return 0; + } else return 0; } diff --git a/src/pazpar2.c b/src/pazpar2.c index f0bd9be..6c3e196 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.51 2007-03-20 07:27:51 adam Exp $ */ +/* $Id: pazpar2.c,v 1.52 2007-03-23 03:26:22 quinn Exp $ */ #include #include @@ -1276,7 +1276,7 @@ int session_active_clients(struct session *s) return res; } -// parses crit1=val1,crit2=val2,... +// parses crit1=val1,crit2=val2|val3,... static struct database_criterion *parse_filter(NMEM m, const char *buf) { struct database_criterion *res = 0; @@ -1289,6 +1289,9 @@ static struct database_criterion *parse_filter(NMEM m, const char *buf) nmem_strsplit(m, ",", buf, &values, &num); for (i = 0; i < num; i++) { + char **subvalues; + int subnum; + int subi; struct database_criterion *new = nmem_malloc(m, sizeof(*new)); char *eq = strchr(values[i], '='); if (!eq) @@ -1298,7 +1301,15 @@ static struct database_criterion *parse_filter(NMEM m, const char *buf) } *(eq++) = '\0'; new->name = values[i]; - new->value = eq; + nmem_strsplit(m, "|", eq, &subvalues, &subnum); + new->values = 0; + for (subi = 0; subi < subnum; subi++) + { + struct database_criterion_value *newv = nmem_malloc(m, sizeof(*newv)); + newv->value = subvalues[subi]; + newv->next = new->values; + new->values = newv; + } new->next = res; res = new; } diff --git a/src/pazpar2.h b/src/pazpar2.h index 5b04d73..7a81537 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -75,9 +75,14 @@ struct database { struct database *next; }; +struct database_criterion_value { + char *value; + struct database_criterion_value *next; +}; + struct database_criterion { char *name; - char *value; + struct database_criterion_value *values; struct database_criterion *next; };