From b57542eb8dfd435b7c5f2c02e4b0d9a1a8431521 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 24 Nov 2011 11:00:10 +0100 Subject: [PATCH] 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. --- src/cql2ccl.c | 4 ++-- test/test_cql2ccl.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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) -- 1.7.10.4