Substring matching for target selectiion.
authorJason Skomorowski <jason@indexdata.com>
Tue, 6 Oct 2009 16:13:44 +0000 (12:13 -0400)
committerJason Skomorowski <jason@indexdata.com>
Tue, 6 Oct 2009 16:13:44 +0000 (12:13 -0400)
src/database.c
src/logic.c
src/pazpar2.h

index 3dfe74e..d51cd4f 100644 (file)
@@ -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
index 8c2d070..697da4d 100644 (file)
@@ -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';
index 76d0fa1..b6771d1 100644 (file)
@@ -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;
 };