Fix CQL to CCL conversion for multiple terms
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 20 Dec 2011 11:56:08 +0000 (12:56 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 20 Dec 2011 11:56:08 +0000 (12:56 +0100)
Add two test cases as well.

src/cql2ccl.c
test/test_cql2ccl.c

index 87881e4..58b5804 100644 (file)
@@ -62,7 +62,7 @@ static void pr_term(const char **cpp, int stop_at_space,
             }
             pr("#", client_data);
         }
-        else if (*cp == ' ')
+        else if (*cp == ' ' && stop_at_space)
             break;
         else
         {
@@ -130,17 +130,20 @@ static int node(struct cql_node *cn,
             {
                 pr(ccl_field, client_data);
                 pr(ccl_rel, client_data);
+                if (!split_op)
+                    ccl_rel = 0;
             }
             pr_term(&cp, split_op ? 1 : 0, pr, client_data);
-            if (!split_op)
-                break;
             while (*cp == ' ')
                 cp++;
             if (*cp == '\0')
                 break;
             pr(" ", client_data);
-            pr(split_op, client_data);
-            pr(" ", client_data);
+            if (split_op)
+            {
+                pr(split_op, client_data);
+                pr(" ", client_data);
+            }
         }
         if (cn->u.st.extra_terms)
         {
index e2f9b5f..482e47a 100644 (file)
@@ -36,7 +36,7 @@ static int tst_query_s(const char *cql, const char *expected_ccl,
             if (!r)
             {
                 ret = 0;
-                yaz_log(YLOG_WARN, "cql: diff %s", cql);
+                yaz_log(YLOG_WARN, "cql: diff: %s", cql);
                 yaz_log(YLOG_WARN, " exp error");
                 yaz_log(YLOG_WARN, " got ccl %s", wrbuf_cstr(w));
             }
@@ -137,6 +137,10 @@ static void tst(void)
     YAZ_CHECK(tst_query("title any x", "title=\"x\""));
     YAZ_CHECK(tst_query("title any x y", "title=\"x\" or title=\"y\""));
     YAZ_CHECK(tst_query("title any \"x y\"", "title=\"x\" or title=\"y\""));
+
+    YAZ_CHECK(tst_query("title = \"x y\"", "title=\"x y\""));
+    YAZ_CHECK(tst_query("title = x y", "title=\"x\" \"y\""));
+
     YAZ_CHECK(tst_query("dc.title=encyclopedia prox dinosaurs",
                         "(dc.title=\"encyclopedia\") % (\"dinosaurs\")"));
     YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<=3 dinosaurs",