From: Jason Skomorowski Date: Tue, 6 Oct 2009 16:13:44 +0000 (-0400) Subject: Substring matching for target selectiion. X-Git-Tag: v1.2.2~29 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=cf9d5ca2ac4403ce3864e429d115a6475636ef35;p=pazpar2-moved-to-github.git Substring matching for target selectiion. --- diff --git a/src/database.c b/src/database.c index 3dfe74e..d51cd4f 100644 --- a/src/database.c +++ b/src/database.c @@ -239,19 +239,34 @@ static int match_criterion(struct setting **settings, } if (!settings[offset]) return 0; - for (v = c->values; v; v = v->next) - { - if (offset == PZ_ID) + if (c->type == PAZPAR2_STRING_MATCH) + for (v = c->values; v; v = v->next) { - if (match_zurl(settings[offset]->value, v->value)) - break; + if (offset == PZ_ID) + { + if (match_zurl(settings[offset]->value, v->value)) + break; + } + else + { + if (!strcmp(settings[offset]->value, v->value)) + break; + } } - else + else if (c->type == PAZPAR2_SUBSTRING_MATCH) + for (v = c->values; v; v = v->next) { - if (!strcmp(settings[offset]->value, v->value)) - break; + if (offset == PZ_ID) + { + if (match_zurl(settings[offset]->value, v->value)) + break; + } + else + { + if (strstr(settings[offset]->value, v->value)) + break; + } } - } if (v) return 1; else diff --git a/src/logic.c b/src/logic.c index 8c2d070..697da4d 100644 --- a/src/logic.c +++ b/src/logic.c @@ -505,10 +505,14 @@ static struct database_criterion *parse_filter(NMEM m, const char *buf) int subnum; int subi; struct database_criterion *new = nmem_malloc(m, sizeof(*new)); - char *eq = strchr(values[i], '='); + char *eq; + if (eq = strchr(values[i], '=')) + new->type = PAZPAR2_STRING_MATCH; + if (eq = strchr(values[i], '~')) + new->type = PAZPAR2_SUBSTRING_MATCH; if (!eq) { - yaz_log(YLOG_WARN, "Missing equal-sign in filter"); + yaz_log(YLOG_WARN, "Missing equal-signi/tilde in filter"); return 0; } *(eq++) = '\0'; diff --git a/src/pazpar2.h b/src/pazpar2.h index 76d0fa1..b6771d1 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -52,6 +52,11 @@ enum pazpar2_error_code { PAZPAR2_LAST_ERROR }; +enum pazpar2_database_criterion_type { + PAZPAR2_STRING_MATCH, + PAZPAR2_SUBSTRING_MATCH +}; + // Represents a (virtual) database on a host struct database { struct host *host; @@ -70,6 +75,7 @@ struct database_criterion_value { struct database_criterion { char *name; + enum pazpar2_database_criterion_type type; struct database_criterion_value *values; struct database_criterion *next; };