X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fcql2ccl.c;h=54b16e733c56c970cfdbe676080e4611d0176d1f;hb=fda1ca39e89e4c7f3479c0a9d2a1e38acfdb46bb;hp=4a3932e2ccd5a0bc012b2834a0d77b336f1d3a3f;hpb=443e78f2e7d7894a1a9cb3cac79e4b1a84ec7a11;p=yaz-moved-to-github.git diff --git a/src/cql2ccl.c b/src/cql2ccl.c index 4a3932e..54b16e7 100644 --- a/src/cql2ccl.c +++ b/src/cql2ccl.c @@ -26,18 +26,65 @@ static void pr_term(struct cql_node *cn, { while (cn) { - const char *cp; - cp = cn->u.st.term; - while (*cp) + if (! *cn->u.st.term) /* empty term special case */ + pr("\"\"", client_data); + else { - char x[2]; - if (*cp == '*') - x[0] = '?'; - else - x[0] = *cp; - x[1] = 0; - pr(x, client_data); - cp++; + const char *cp; + int quote_mode = 0; + for (cp = cn->u.st.term; *cp; cp++) + { + char x[4]; + + if (*cp == '\\' && cp[1]) + { + if (!quote_mode) + { + pr("\"", client_data); + quote_mode = 1; + } + cp++; + if (*cp == '\"' || *cp == '\\') + pr("\\\"", client_data); + else + { + x[0] = *cp; + x[1] = '\0'; + pr(x, client_data); + } + } + else if (*cp == '*') + { + if (quote_mode) + { + pr("\"", client_data); + quote_mode = 0; + } + pr("?", client_data); + } + else if (*cp == '?') + { + if (quote_mode) + { + pr("\"", client_data); + quote_mode = 0; + } + pr("#", client_data); + } + else + { + if (!quote_mode) + { + pr("\"", client_data); + quote_mode = 1; + } + x[0] = *cp; + x[1] = '\0'; + pr(x, client_data); + } + } + if (quote_mode) + pr("\"", client_data); } if (cn->u.st.extra_terms) pr(" ", client_data); @@ -136,16 +183,60 @@ static int bool(struct cql_node *cn, char *value = cn->u.boolean.value; int r; - /* Rather lame initial attempt at interpreting proximity */ - if (!strcmp(value, "prox")) value = "!"; - pr("(", client_data); r = cql_to_ccl_r(cn->u.boolean.left, pr, client_data); if (r) return r; pr(" ", client_data); - pr(value, client_data); + + if (strcmp(value, "prox")) + { /* not proximity. assuming boolean */ + pr(value, client_data); + } + else + { + struct cql_node *n = cn->u.boolean.modifiers; + int ordered = 0; + int distance = 1; + for (; n ; n = n->u.st.modifiers) + if (n->which == CQL_NODE_ST) + { + if (!strcmp(n->u.st.index, "unit")) + { + if (!strcmp(n->u.st.term, "word")) + ; + else + return -1; + } + else if (!strcmp(n->u.st.index, "distance")) + { + if (!strcmp(n->u.st.relation, "<=")) + distance = atoi(n->u.st.term); + else if (!strcmp(n->u.st.relation, "<")) + distance = atoi(n->u.st.term) - 1; + else + return -1; + } + else if (!strcmp(n->u.st.index, "unordered")) + { + ordered = 0; + } + else if (!strcmp(n->u.st.index, "ordered")) + { + ordered = 1; + } + else + return -1; + } + pr(ordered ? "!" : "%", client_data); + if (distance != 1) + { + char x[40]; + sprintf(x, "%d", distance); + pr(x, client_data); + } + } pr(" ", client_data); r = cql_to_ccl_r(cn->u.boolean.right, pr, client_data);