Fixed serialization of regex in VCs

Change-Id: I2d21d3a37a69c37376a174cf16a4bd0a084e9e78
diff --git a/Changes b/Changes
index e495bcd..0d4ef61 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.24 2017-05-03
+	- Fixed serialization of regexes for VCs (diewald)
+
 0.23 2016-10-27
 	- Added tests and comments for FCSQL (margaretha)
 	- Added quantifier for FCSQL QueryGroup (margaretha)
diff --git a/pom.xml b/pom.xml
index d238e66..0e02382 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
 
 	<groupId>de.ids_mannheim.korap</groupId>
 	<artifactId>Koral</artifactId>
-	<version>0.23</version>
+	<version>0.24</version>
 	<packaging>jar</packaging>
 	<name>Koral</name>
 	<url>http://maven.apache.org</url>
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index df1ca73..ba9ab97 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -277,13 +277,21 @@
         if (stm.startsWith("\"") && stm.endsWith("\""))
             stm = stm.replaceAll("\"", "");
 
-        if ("regex".equals(node_cat) | "multiword".equals(node_cat))
+        if ("regex".equals(node_cat)) {
+			
+            map.put("type", "type:regex");
+
+			// remove leading and trailing slashes
+			if (stm.startsWith("/") && stm.endsWith("/")) {
+				stm = stm.substring(1, stm.length() - 1);
+			};
+            map.put("value", stm);
+		}
+		else if ("multiword".equals(node_cat))
             map.put("value", stm);
         else
             map.put("value", valueNode.getChild(0).toStringTree(parser));
 
-        if ("regex".equals(node_cat))
-            map.put("type", "type:regex");
         return map;
     }
 
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 a88278f..04a081f 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
@@ -14,6 +14,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 public class CollectionQueryProcessorTest {
 
@@ -47,6 +48,7 @@
         assertEquals("koral:doc", res.at("/collection/@type").asText());
         assertEquals("textClass", res.at("/collection/key").asText());
         assertEquals("politik", res.at("/collection/value").asText());
+        assertFalse(res.at("/collection/type").asText().equals("type:regex"));
         assertEquals("match:eq", res.at("/collection/match").asText());
 
         collection = "textClass!=politik";
@@ -56,6 +58,7 @@
         assertEquals("koral:doc", res.at("/collection/@type").asText());
         assertEquals("textClass", res.at("/collection/key").asText());
         assertEquals("politik", res.at("/collection/value").asText());
+        assertFalse(res.at("/collection/type").asText().equals("type:regex"));
         assertEquals("match:ne", res.at("/collection/match").asText());
     }
 
@@ -110,6 +113,21 @@
     }
 
 
+	@Test
+    public void testRegex () throws JsonProcessingException, IOException {
+        collection = "textClass=/politik/";
+        qs.setQuery(query, ql);
+        qs.setCollection(collection);
+        res = mapper.readTree(qs.toJSON());
+        assertEquals("koral:doc", res.at("/collection/@type").asText());
+        assertEquals("textClass", res.at("/collection/key").asText());
+        assertEquals("politik", res.at("/collection/value").asText());
+        assertEquals("type:regex", res.at("/collection/type").asText());
+        assertEquals("match:eq", res.at("/collection/match").asText());
+    }
+
+
+
     @Test
     public void testNotDate () throws JsonProcessingException, IOException {
         collection = "author=\"firefighter1974\"";
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 6f3dd6d..d32195c 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
@@ -185,7 +185,7 @@
         query = "wegen #IN(N, MAX) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res.toString());
+        // System.out.println(res.toString());
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:focus", res.at("/query/operation").asText());
         assertEquals(130, res.at("/query/classRef/0").asInt());
@@ -202,7 +202,7 @@
         query = "wegen #IN(N, HIT) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res.toString());
+        // System.out.println(res.toString());
         assertEquals("koral:reference", res.at("/query/@type").asText());
         assertEquals("operation:focus", res.at("/query/operation").asText());
         assertEquals(130, res.at("/query/classRef/0").asInt());
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 734f8d7..3246141 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
@@ -203,7 +203,7 @@
         query = "wegen #IN(N,ALL,%) <s>";
         qs.setQuery(query, "cosmas2");
         res = mapper.readTree(qs.toJSON());
-        System.out.println(res.toString());
+        // System.out.println(res.toString());
         assertEquals("operation:class", res.at("/query/operation").asText());
         assertEquals("classRefOp:delete", res.at("/query/classRefOp").asText());
         assertEquals(131, res.at("/query/classIn/0").asInt());