Added a CQL AND query test.

Change-Id: I193979703d45f12f975f03f4dc38b64a9d0e998b

Change-Id: I193979703d45f12f975f03f4dc38b64a9d0e998b
diff --git a/Changes b/Changes
index 313a31a..6e363e0 100644
--- a/Changes
+++ b/Changes
@@ -9,6 +9,7 @@
       from JSON responses (diewald)
     - [bugfix] Do not optimize %+w1:1 to be a treated like /+w1:1
       (diewald)
+    - [cleanup] Added a CQL AND query test (margaretha)  
 
 0.58.5 2019-03-18
     - [bugfix] Fix bug where duplicate keys occured in
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
index ae9d26f..0e07964 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
@@ -36,7 +36,6 @@
     Result kr;
     KrillIndex ki;
 
-
     private FieldDocument createFieldDoc0 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-0");
@@ -51,7 +50,6 @@
         return fd;
     }
 
-
     private FieldDocument createFieldDoc1 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-1");
@@ -65,7 +63,6 @@
         return fd;
     }
 
-
     private FieldDocument createFieldDoc2 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-2");
@@ -79,7 +76,6 @@
         return fd;
     }
 
-
     private FieldDocument createFieldDoc3 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-3");
@@ -92,7 +88,7 @@
                         + "[(5-6)s:d|_6$<i>5<i>6]");
         return fd;
     }
-    
+
     private FieldDocument createFieldDoc4 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-4");
@@ -106,7 +102,6 @@
         return fd;
     }
 
-
     public SpanQuery createQuery (String elementType, String x, String y,
             int min, int max, boolean isOrdered) {
 
@@ -116,7 +111,6 @@
                 new DistanceConstraint(e, min, max, isOrdered, false), true);
     }
 
-
     /**
      * Multiple documents
      * Ensure terms and elements are in the same doc
@@ -149,7 +143,7 @@
 
     /**
      * Ignore nested element distance unit
-     * */
+     */
     @Test
     public void testCase1b () throws IOException {
         ki = new KrillIndex();
@@ -168,7 +162,6 @@
         assertEquals(4, kr.getMatch(1).endPos);
     }
 
-    
     /**
      * Ensure terms and elements are in the same doc
      */
@@ -191,7 +184,6 @@
 
     }
 
-
     /** Skip to */
     @Test
     public void testCase3 () throws IOException {
@@ -216,7 +208,6 @@
 
     }
 
-
     /** Same tokens in different elements */
     @Test
     public void testCase4 () throws IOException {
@@ -236,7 +227,6 @@
 
     }
 
-
     /** Test query from json */
     @Test
     public void testCase5 () throws Exception {
@@ -244,7 +234,8 @@
         ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
         ki.commit();
 
-        String jsonPath = getClass().getResource("/queries/cosmas1.json").getFile();
+        String jsonPath =
+                getClass().getResource("/queries/cosmas1.json").getFile();
         SpanQueryWrapper sqwi = getJsonQuery(jsonPath);
         kr = ki.search(sqwi.toQuery(), (short) 10);
 
@@ -255,6 +246,24 @@
         assertEquals(33, kr.getMatch(1).endPos);
     }
 
+    @Test
+    public void testCQLAnd () throws Exception {
+        ki = new KrillIndex();
+        ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
+        ki.commit();
+
+        String jsonPath = getClass()
+                .getResource("/queries/distances/cql-and.jsonld").getFile();
+        SpanQueryWrapper sqwi = getJsonQuery(jsonPath);
+        SpanQuery query = sqwi.toQuery();
+        assertEquals(
+                "spanElementDistance(tokens:s:Buchstaben, tokens:s:Alphabet, "
+                        + "[(base/s:s[0:0], notOrdered, notExcluded)])",
+                query.toString());
+        kr = ki.search(sqwi.toQuery(), (short) 10);
+
+        assertEquals((long) 1, kr.getTotalResults());
+    }
 
     /** Test query from json (2) */
     @Test
@@ -281,7 +290,9 @@
                 sqwi.toQuery().toString());
 
         kr = ki.search(sqwi.toQuery(), (short) 10);
-        assertEquals(1, kr.getTotalResults()); // Is 1 correct or should it not be ordered?
+        assertEquals(1, kr.getTotalResults()); // Is 1 correct or
+                                               // should it not be
+                                               // ordered?
         assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
     }
 }
diff --git a/src/test/resources/queries/distances/cql-and.jsonld b/src/test/resources/queries/distances/cql-and.jsonld
new file mode 100644
index 0000000..517a62a
--- /dev/null
+++ b/src/test/resources/queries/distances/cql-and.jsonld
@@ -0,0 +1,51 @@
+{
+    "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+    "query": {
+        "@type": "koral:group",
+        "distances": [{
+            "@type": "cosmas:distance",
+            "key": "s",
+	    "boundary": {
+		"@type": "koral:boundary",
+		"max": "0",
+		"min": "0"
+	    }
+        }],
+        "inOrder": false,
+        "operands": [
+            {
+                "@type": "koral:token",
+                "wrap": {
+                    "@type": "koral:term",
+                    "foundry": "opennlp",
+                    "key": "Buchstaben",
+                    "layer": "orth",
+                    "match": "match:eq",
+                    "rewrites": [{
+                        "@type": "koral:rewrite",
+                        "operation": "operation:injection",
+                        "scope": "foundry",
+                        "src": "Kustvakt"
+                    }]
+                }
+            },
+            {
+                "@type": "koral:token",
+                "wrap": {
+                    "@type": "koral:term",
+                    "foundry": "opennlp",
+                    "key": "Alphabet",
+                    "layer": "orth",
+                    "match": "match:eq",
+                    "rewrites": [{
+                        "@type": "koral:rewrite",
+                        "operation": "operation:injection",
+                        "scope": "foundry",
+                        "src": "Kustvakt"
+                    }]
+                }
+            }
+        ],
+        "operation": "operation:sequence"
+    }
+}