Revert "Remove HDCQL functionality"
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 12 Apr 2013 12:16:37 +0000 (14:16 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 12 Apr 2013 12:16:37 +0000 (14:16 +0200)
This reverts commit 9084e20f4c5ffad9cfea2087396206b75a3a6654.

17 files changed:
src/cql.y
src/cql2ccl.c
src/cqltransform.c
src/xcqlutil.c
test/cql/11.1.err
test/cql/11.1.out
test/cql/11.2.out
test/cql/11.3.err
test/cql/11.3.out
test/cql/11.4.out
test/cql/11.5.err
test/cql/11.5.out
test/cql/11.7.err
test/cql/11.7.out
test/cql2pqf/1.2.err
test/cql2pqf/1.2.out
test/test_cql2ccl.c

index 67e2f76..ea828dc 100644 (file)
--- a/src/cql.y
+++ b/src/cql.y
@@ -56,7 +56,7 @@
 %}
 
 %pure_parser
-%token SIMPLE_STRING AND OR NOT PROX GE LE NE EXACT SORTBY
+%token PREFIX_NAME SIMPLE_STRING AND OR NOT PROX GE LE NE EXACT SORTBY
 
 %%
 
@@ -145,12 +145,12 @@ searchClause:
       $$.cql = $3.cql;
   }
 |
-searchTerm {
+searchTerm extraTerms {
       struct cql_node *st = cql_node_dup(((CQL_parser) parm)->nmem, $0.rel);
+      st->u.st.extra_terms = $2.cql;
       st->u.st.term = nmem_strdup(((CQL_parser)parm)->nmem, $1.buf);
       $$.cql = st;
   }
-
 |
   index relation modifiers {
       $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, $1.buf, $2.buf, 0);
@@ -161,6 +161,18 @@ searchTerm {
   }
 ;
 
+extraTerms:
+SIMPLE_STRING extraTerms {
+    struct cql_node *st = cql_node_mk_sc(((CQL_parser) parm)->nmem,
+                                        /* index */ 0, /* rel */ 0, $1.buf);
+    st->u.st.extra_terms = $2.cql;
+    $$.cql = st;
+}
+|
+{ $$.cql = 0; }
+;
+
+
 /* unary NOT search SIMPLE_STRING here .. */
 
 boolean:
@@ -189,7 +201,7 @@ modifiers '/' searchTerm relation_symbol searchTerm
 }
 ;
 
-relation: SIMPLE_STRING | relation_symbol;
+relation: PREFIX_NAME | relation_symbol;
 
 relation_symbol:
   '='
@@ -206,6 +218,7 @@ index:
 
 searchTerm:
   SIMPLE_STRING
+| PREFIX_NAME
 | AND
 | OR
 | NOT
@@ -325,8 +338,11 @@ int yylex(YYSTYPE *lval, void *vp)
     }
     else
     {
+       int relation_like = 0;
        while (c != 0 && !strchr(" \n()=<>/", c))
        {
+           if (c == '.')
+               relation_like = 1;
            if (c == '\\')
            {
                putb(lval, cp, c);
@@ -368,6 +384,18 @@ int yylex(YYSTYPE *lval, void *vp)
            lval->buf = "sortby";
            return SORTBY;
        }
+       if (!cql_strcmp(lval->buf, "all"))
+           relation_like = 1;
+       if (!cql_strcmp(lval->buf, "any"))
+           relation_like = 1;
+       if (!cql_strcmp(lval->buf, "adj"))
+           relation_like = 1;
+       if (!cql_strcmp(lval->buf, "within"))
+           relation_like = 1;
+       if (!cql_strcmp(lval->buf, "encloses"))
+           relation_like = 1;
+       if (relation_like)
+           return PREFIX_NAME;
     }
     return SIMPLE_STRING;
 }
index 331b6db..81e2c5f 100644 (file)
@@ -91,7 +91,6 @@ static int node(struct cql_node *cn,
     const char *split_op = 0;
     const char *ccl_rel = 0;
     const char *rel = cn->u.st.relation;
-    const char *cp;
 
     if (cn->u.st.index && strcmp(cn->u.st.index,
                                  "cql.serverChoice"))
@@ -122,26 +121,38 @@ static int node(struct cql_node *cn,
         /* unsupported relation */
         return -1;
     }
-    cp = cn->u.st.term;
-    while (1)
+    for (; cn; cn = cn->u.st.extra_terms)
     {
-        if (ccl_field && ccl_rel)
+        const char *cp = cn->u.st.term;
+        while (1)
         {
-            pr(ccl_field, client_data);
-            pr(ccl_rel, client_data);
-            if (!split_op)
-                ccl_rel = 0;
+            if (ccl_field && ccl_rel)
+            {
+                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);
+            while (*cp == ' ')
+                cp++;
+            if (*cp == '\0')
+                break;
+            pr(" ", client_data);
+            if (split_op)
+            {
+                pr(split_op, client_data);
+                pr(" ", client_data);
+            }
         }
-        pr_term(&cp, split_op ? 1 : 0, pr, client_data);
-        while (*cp == ' ')
-            cp++;
-        if (*cp == '\0')
-            break;
-        pr(" ", client_data);
-        if (split_op)
+        if (cn->u.st.extra_terms)
         {
-            pr(split_op, client_data);
             pr(" ", client_data);
+            if (split_op)
+            {
+                pr(split_op, client_data);
+                pr(" ", client_data);
+            }
         }
     }
     return 0;
index 90dcb37..8253e50 100644 (file)
@@ -762,10 +762,29 @@ static void emit_term(cql_transform_t ct,
 static void emit_terms(cql_transform_t ct,
                        struct cql_node *cn,
                        void (*pr)(const char *buf, void *client_data),
-                       void *client_data)
+                       void *client_data,
+                       const char *op)
 {
+    struct cql_node *ne = cn->u.st.extra_terms;
+    if (ne)
+    {
+        (*pr)("@", client_data);
+        (*pr)(op, client_data);
+        (*pr)(" ", client_data);
+    }
     emit_term(ct, cn, cn->u.st.term, strlen(cn->u.st.term),
               pr, client_data);
+    for (; ne; ne = ne->u.st.extra_terms)
+    {
+        if (ne->u.st.extra_terms)
+        {
+            (*pr)("@", client_data);
+            (*pr)(op, client_data);
+            (*pr)(" ", client_data);
+        }
+        emit_term(ct, cn, ne->u.st.term, strlen(ne->u.st.term),
+                  pr, client_data);
+    }
 }
 
 static void emit_wordlist(cql_transform_t ct,
@@ -844,7 +863,7 @@ void cql_transform_r(cql_transform_t ct,
         else if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, "any"))
             emit_wordlist(ct, cn, pr, client_data, "or");
         else
-            emit_terms(ct, cn, pr, client_data);
+            emit_terms(ct, cn, pr, client_data, "and");
         break;
     case CQL_NODE_BOOL:
         (*pr)("@", client_data);
index de6116c..fe75f0b 100644 (file)
@@ -188,6 +188,16 @@ static void cql_to_xml_r(struct cql_node *cn,
             pr_cdata(cn->u.st.term, pr, client_data);
             pr_n("</term>\n", pr, client_data, 0);
         }
+        if (cn->u.st.extra_terms)
+        {
+            struct cql_node *n = cn->u.st.extra_terms;
+            for (; n; n = n->u.st.extra_terms)
+            {
+                pr_n("<term>", pr, client_data, level+2);
+                pr_cdata(n->u.st.term, pr, client_data);
+                pr_n("</term>\n", pr, client_data, 0);
+            }
+        }
         cql_sort_to_xml(sort_node, pr, client_data, level+2);
         pr_n("</searchClause>\n", pr, client_data, level);
         break;
index f83d884..e69de29 100644 (file)
@@ -1 +0,0 @@
-Syntax error
index e69de29..a8ff186 100644 (file)
@@ -0,0 +1,8 @@
+<searchClause>
+  <index>cql.serverChoice</index>
+  <relation>
+    <value>=</value>
+  </relation>
+  <term>a</term>
+  <term>b</term>
+</searchClause>
index 88c7cb3..aaa51fb 100644 (file)
@@ -1,7 +1,9 @@
 <searchClause>
-  <index>a</index>
+  <index>cql.serverChoice</index>
   <relation>
-    <value>b</value>
+    <value>=</value>
   </relation>
+  <term>a</term>
+  <term>b</term>
   <term>c</term>
 </searchClause>
index f83d884..e69de29 100644 (file)
@@ -1 +0,0 @@
-Syntax error
index e69de29..3a66149 100644 (file)
@@ -0,0 +1,8 @@
+<searchClause>
+  <index>cql.serverChoice</index>
+  <relation>
+    <value>=</value>
+  </relation>
+  <term>a.b</term>
+  <term>c</term>
+</searchClause>
index b5c4126..ef54784 100644 (file)
@@ -1,7 +1,9 @@
 <searchClause>
-  <index>and</index>
+  <index>cql.serverChoice</index>
   <relation>
-    <value>b</value>
+    <value>=</value>
   </relation>
+  <term>and</term>
+  <term>b</term>
   <term>c</term>
 </searchClause>
index f83d884..e69de29 100644 (file)
@@ -1 +0,0 @@
-Syntax error
index e69de29..50f2571 100644 (file)
@@ -0,0 +1,8 @@
+<searchClause>
+  <index>cql.serverChoice</index>
+  <relation>
+    <value>=</value>
+  </relation>
+  <term>all</term>
+  <term>a</term>
+</searchClause>
index f83d884..e69de29 100644 (file)
@@ -1 +0,0 @@
-Syntax error
index e69de29..0d59eb1 100644 (file)
@@ -0,0 +1,26 @@
+<triple>
+  <boolean>
+    <value>and</value>
+  </boolean>
+  <leftOperand>
+    <searchClause>
+      <index>cql.serverChoice</index>
+      <relation>
+        <value>=</value>
+      </relation>
+      <term>dc.title</term>
+      <term>a</term>
+      <term>b</term>
+      <term>c</term>
+    </searchClause>
+  </leftOperand>
+  <rightOperand>
+    <searchClause>
+      <index>cql.serverChoice</index>
+      <relation>
+        <value>=</value>
+      </relation>
+      <term>d</term>
+    </searchClause>
+  </rightOperand>
+</triple>
index f83d884..e69de29 100644 (file)
@@ -1 +0,0 @@
-Syntax error
index c4d2fb1..413ec53 100644 (file)
@@ -1 +1,2 @@
 Parsing CQL a b
+@attr 6=1 @attr 2=3 @attr 4=1 @and @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a" @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "b" 
index 06a1c61..b52ad14 100644 (file)
@@ -110,7 +110,8 @@ static void tst(void)
     YAZ_CHECK(tst_query("\\*", "\"*\""));
     YAZ_CHECK(tst_query("\"\\*\"", "\"*\""));
 
-    YAZ_CHECK(tst_query("\"a b\"", "\"a b\""));
+    YAZ_CHECK(tst_query("a b", "\"a\" \"b\""));
+    YAZ_CHECK(tst_query("ab bc", "\"ab\" \"bc\""));
 
     YAZ_CHECK(tst_query("\\\\", "\"\\\\\""));
     YAZ_CHECK(tst_query("\\\"", "\"\\\"\""));
@@ -130,12 +131,17 @@ static void tst(void)
     YAZ_CHECK(tst_query("title all \"\"", "title=\"\""));
 
     YAZ_CHECK(tst_query("title all x", "title=\"x\""));
+    YAZ_CHECK(tst_query("title all x y", "title=\"x\" and title=\"y\""));
     YAZ_CHECK(tst_query("title all \"x y\"", "title=\"x\" and title=\"y\""));
 
     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("title = x y z",  "title=\"x\" \"y\" \"z\""));
 
     YAZ_CHECK(tst_query("dc.title=encyclopedia prox dinosaurs",
                         "(dc.title=\"encyclopedia\") % (\"dinosaurs\")"));