Fixed greediness of regex in collection queries

Change-Id: If2b58b73222a157e50e0b22f560a47367dc8b1f3
diff --git a/Changes b/Changes
index 677c1a5..912ea72 100644
--- a/Changes
+++ b/Changes
@@ -1,9 +1,11 @@
-0.28 2017-11-30 
+0.28 2018-01-08
 	- Added some enums for koral:operation (margaretha)
 	- Fixed node serialization of Annis QL containing lemma (margaretha)
 	- Added serialization for Annis keyword "lemma" (margaretha)
 	- Removed version from FCSQL processor (margaretha)
 	- Fixed Annis regex bug regarding slash after foundry (margaretha)
+  - Fixed use of regular expressions in corpus queries
+    (margaretha, diewald)
 	
 0.27 2017-09-12
 	- Changed Cosmas2 wildcards serialization as regex (margaretha)  
diff --git a/src/main/antlr/collection/CollectionQueryLexer.g4 b/src/main/antlr/collection/CollectionQueryLexer.g4
index 418e87c..059ad82 100644
--- a/src/main/antlr/collection/CollectionQueryLexer.g4
+++ b/src/main/antlr/collection/CollectionQueryLexer.g4
@@ -63,7 +63,7 @@
 WORD				: ALPHABET+;
 //WORD                : ALPHABET* ALPHA ALPHABET*;  // needs to have at least one alphabetical letter (non-numeric)
 
-REGEX     		     : SLASH .* SLASH; 
+REGEX     		     : SLASH .*? SLASH; 
 
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
index 563603e..24b3e72 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
@@ -118,7 +118,6 @@
         qs.setQuery(query, ql);
         qs.setCollection(collection);
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
         assertEquals("koral:doc", res.at("/collection/@type").asText());
         assertEquals("textClass", res.at("/collection/key").asText());
         assertEquals("politik", res.at("/collection/value").asText());
@@ -137,6 +136,25 @@
         assertEquals("politik", res.at("/collection/value").asText());
         assertEquals("type:regex", res.at("/collection/type").asText());
         assertEquals("match:eq", res.at("/collection/match").asText());
+
+        collection = "textClass=/politik/ or textClass=/kultur.*/";
+        qs.setQuery(query, ql);
+        qs.setCollection(collection);
+        res = mapper.readTree(qs.toJSON());
+        assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+        assertEquals("operation:or", res.at("/collection/operation").asText());
+
+        assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
+        assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+        assertEquals("politik", res.at("/collection/operands/0/value").asText());
+        assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
+        assertEquals("type:regex", res.at("/collection/operands/0/type").asText());
+
+		assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
+        assertEquals("textClass", res.at("/collection/operands/1/key").asText());
+        assertEquals("kultur.*", res.at("/collection/operands/1/value").asText());
+        assertEquals("match:eq", res.at("/collection/operands/1/match").asText());
+        assertEquals("type:regex", res.at("/collection/operands/1/type").asText());
     }
 
 	@Test
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
index 5de3405..d2bfcff 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/Cosmas2QueryProcessorTest.java
@@ -708,7 +708,7 @@
         query = "wegen #OV <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation")
                 .asText());
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
index 9e3712c..9c6e172 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINTest.java
@@ -29,7 +29,7 @@
         query = "wegen #IN <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:position", res.at("/query/operation").asText());
         assertEquals(4, res.at("/query/frames").size());
@@ -253,7 +253,7 @@
         query = "gilt #IN(FE,HIT) (&gelten /w5:10 zurecht)";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation").asText());
 
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
index 6cb5ffb..062bc20 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPINWithExclusionTest.java
@@ -317,7 +317,7 @@
         query = "wegen #IN(N,HIT,%) (wegen /w5:10 des)";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:exclusion",
                 res.at("/query/operation").asText());
diff --git a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
index 3b2bcd7..a9b19ef 100644
--- a/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/cosmas2/OPOVWithExclusionTest.java
@@ -62,7 +62,7 @@
         query = "wegen #OV(%, L) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
 
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation").asText());
@@ -99,7 +99,7 @@
         query = "wegen #OV(%, R) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
 
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation").asText());
@@ -140,7 +140,7 @@
         query = "wegen #OV(%, FE) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res);
+        // System.out.println(res);
 
         assertEquals("koral:group", res.at("/query/@type").asText());
         assertEquals("operation:class", res.at("/query/operation").asText());