From: Adam Dickmeiss Date: Thu, 24 Nov 2011 10:00:10 +0000 (+0100) Subject: CQL to CCL: add ()s for boolean sub terms X-Git-Tag: v4.2.22~4 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=b57542eb8dfd435b7c5f2c02e4b0d9a1a8431521;p=yaz-moved-to-github.git CQL to CCL: add ()s for boolean sub terms For boolean operation, a op b, make CCL (a) op (b) rather than (a op b), to ensure that proximity operator within a or be is only applied there. This is to ensure that field assigment in a is never applied to b in the resulting CQL. In CCL proximity has higher precedence than field assignment, unlike CQL. --- diff --git a/src/cql2ccl.c b/src/cql2ccl.c index d7d05cc..87881e4 100644 --- a/src/cql2ccl.c +++ b/src/cql2ccl.c @@ -168,7 +168,7 @@ static int bool(struct cql_node *cn, if (r) return r; - pr(" ", client_data); + pr(") ", client_data); if (strcmp(value, "prox")) { /* not proximity. assuming boolean */ @@ -217,7 +217,7 @@ static int bool(struct cql_node *cn, pr(x, client_data); } } - pr(" ", client_data); + pr(" (", client_data); r = cql_to_ccl_r(cn->u.boolean.right, pr, client_data); pr(")", client_data); diff --git a/test/test_cql2ccl.c b/test/test_cql2ccl.c index 0f2cdd2..c2bb9e3 100644 --- a/test/test_cql2ccl.c +++ b/test/test_cql2ccl.c @@ -88,7 +88,9 @@ static void tst(void) YAZ_CHECK(tst_query("title=x", "title=\"x\"")); YAZ_CHECK(tst_query("title=x or author=y", - "(title=\"x\" or author=\"y\")")); + "(title=\"x\") or (author=\"y\")")); + YAZ_CHECK(tst_query("title=x or author=y and date=z", + "((title=\"x\") or (author=\"y\")) and (date=\"z\")")); YAZ_CHECK(tst_query("title all \"\"", "title=\"\"")); @@ -99,6 +101,8 @@ 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("dc.title=encyclopedia prox dinosaurs", + "(dc.title=\"encyclopedia\") % (\"dinosaurs\")")); } int main(int argc, char **argv)