Implement limitmap OR. Bug #4675
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Sep 2011 14:12:33 +0000 (16:12 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Sep 2011 14:12:33 +0000 (16:12 +0200)
This requires nmem_strsplit_escape2 from YAZ.

src/client.c
src/facet_limit.c
test/test_http.urls

index 5bebb59..308364d 100644 (file)
@@ -939,6 +939,7 @@ static void apply_limit(struct session_database *sdb,
     int i = 0;
     const char *name;
     const char *value;
+    NMEM nmem_tmp = nmem_create();
     for (i = 0; (name = facet_limits_get(facet_limits, i, &value)); i++)
     {
         struct setting *s = 0;
@@ -948,32 +949,55 @@ static void apply_limit(struct session_database *sdb,
             const char *p = strchr(s->name + 3, ':');
             if (p && !strcmp(p + 1, name) && s->value)
             {
+                char **values = 0;
+                int i, num = 0;
+                nmem_strsplit_escape2(nmem_tmp, "|", value, &values,
+                                      &num, 1, '\\', 1);
+
                 if (!strncmp(s->value, "rpn:", 4))
                 {
                     const char *pqf = s->value + 4;
+
                     wrbuf_puts(w_pqf, "@and ");
                     wrbuf_puts(w_pqf, pqf);
                     wrbuf_puts(w_pqf, " ");
-                    yaz_encode_pqf_term(w_pqf, value, strlen(value));
+                    for (i = 0; i < num; i++)
+                    {
+                        if (i < num - 1)
+                            wrbuf_puts(w_pqf, "@or ");
+                        yaz_encode_pqf_term(w_pqf, values[i],
+                                            strlen(values[i]));
+                    }
                 }
                 else if (!strncmp(s->value, "ccl:", 4))
                 {
                     const char *ccl = s->value + 4;
-                    wrbuf_puts(w_ccl, " and ");
-                    wrbuf_puts(w_ccl, ccl);
-                    wrbuf_puts(w_ccl, "=\"");
-                    wrbuf_puts(w_ccl, value);
-                    wrbuf_puts(w_ccl, "\"");
+
+                    wrbuf_puts(w_ccl, " and (");
+
+                    for (i = 0; i < num; i++)
+                    {
+                        if (i)
+                            wrbuf_puts(w_ccl, " or ");
+                        wrbuf_puts(w_ccl, ccl);
+                        wrbuf_puts(w_ccl, "=\"");
+                        wrbuf_puts(w_ccl, values[i]);
+                        wrbuf_puts(w_ccl, "\"");
+                    }
+                    wrbuf_puts(w_ccl, ")");
+
                 }
                 break;
             }
         }
+        nmem_reset(nmem_tmp);
         if (!s)
         {
             yaz_log(YLOG_WARN, "Target %s: limit %s used, but no limitmap defined",
                     (sdb->database ? sdb->database->url : "<no url>"), name);
         }
     }
+    nmem_destroy(nmem_tmp);
 }
                         
 // Parse the query given the settings specific to this client
index dca5c29..44bcff0 100644 (file)
@@ -48,8 +48,8 @@ facet_limits_t facet_limits_create(const char *param)
     fl->num = 0;
     fl->darray = 0;
     if (param)
-        nmem_strsplit_escape(fl->nmem, ",", param, &fl->darray,
-                             &fl->num, 1, '\\');
+        nmem_strsplit_escape2(fl->nmem, ",", param, &fl->darray,
+                              &fl->num, 1, '\\', 0);
     /* replace = with \0 .. for each item */
     for (i = 0; i < fl->num; i++)
     {
index 945d805..eb3828f 100644 (file)
@@ -56,8 +56,8 @@ http://localhost:9763/search.pz2?session=8&command=search&query=xyzzyz
 http://localhost:9763/search.pz2?session=8&command=search&query=a+and
 1 http://localhost:9763/search.pz2?session=8&command=show&block=1
 http://localhost:9763/search.pz2?command=init&pz:limitmap:author%5Bz3950.indexdata.com%2Fmarc%5D=ccl:author_phrase
-1 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3dadam\,+james
+1 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3dadam\,+james%7Cother_author
 1 http://localhost:9763/search.pz2?session=9&command=show&block=1
 http://localhost:9763/search.pz2?session=9&command=settings&pz:limitmap:author%5Bz3950.indexdata.com%2Fmarc%5D=rpn:%40attr+1%3d1003+%40attr+6%3d3
-1 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3dadam\,+james
+1 http://localhost:9763/search.pz2?session=9&command=search&query=greece&limit=author%3dadam\,+james%7Cother_author
 1 http://localhost:9763/search.pz2?session=9&command=show&block=1