'add to meta object, not replace it' bug fix
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
index fa9f3fc..3dfcb12 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder.java
@@ -55,7 +55,7 @@
         return this;
     }
 
-    @Deprecated
+
     public CollectionQueryBuilder addMetaFilterQuery(String queries) {
         this.mfilter.putAll(resRel(queries));
         return this;
@@ -78,12 +78,12 @@
         return this;
     }
 
-    @Deprecated
     public CollectionQueryBuilder addMetaExtendQuery(String queries) {
         this.mextension.putAll(resRel(queries));
         return this;
     }
 
+
     @Deprecated
     private List<Map> createFilter(Relation rel) {
         String relation = rel == Relation.AND ? "and" : "or";
@@ -254,9 +254,16 @@
      */
     private Multimap<String, String> resRel(String queries) {
         Multimap<String, String> qmap = ArrayListMultimap.create();
-        String rel = queries.contains("AND") ? "AND" : "OR";
+        String op = null;
+        if (queries.contains("AND") | queries.contains("OR"))
+            op = queries.contains("AND") ? "AND" : "OR";
+        else if (queries.contains("&") | queries.contains("|"))
+            op = queries.contains("&") ? "&" : "|";
 
-        String[] spl = queries.trim().split(rel);
+        if (op == null)
+            return qmap;
+
+        String[] spl = queries.trim().split(op);
         for (String query : spl) {
             String[] q = query.split("=");
             if (q.length > 1) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder3.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder3.java
new file mode 100644
index 0000000..786ab94
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder3.java
@@ -0,0 +1,82 @@
+package de.ids_mannheim.korap.query.serialize;
+
+import de.ids_mannheim.korap.util.QueryException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * convenience builder class for collection query -- new one
+ *
+ * @author hanl
+ * @date 16/09/2014
+ */
+public class CollectionQueryBuilder3 {
+
+    private boolean verbose;
+    private List<Map> rq;
+    private StringBuilder builder;
+
+    public CollectionQueryBuilder3() {
+        this(false);
+    }
+
+    public CollectionQueryBuilder3(boolean verbose) {
+        this.verbose = verbose;
+        this.builder = new StringBuilder();
+        this.rq = new LinkedList<>();
+    }
+
+
+    public CollectionQueryBuilder3 addSegment(String field, String value) {
+        String f = field + "=" + value;
+        this.builder.append(f);
+        return this;
+    }
+
+    public CollectionQueryBuilder3 add(String query) {
+        this.builder.append(query);
+        return this;
+    }
+
+    public CollectionQueryBuilder3 and() {
+        this.builder.append(" & ");
+        return this;
+    }
+
+    public CollectionQueryBuilder3 or() {
+        this.builder.append(" | ");
+        return this;
+    }
+
+    public CollectionQueryBuilder3 addResource(String collection) {
+        try {
+            List v = JsonUtils.read(collection, LinkedList.class);
+            this.rq.addAll(v);
+        } catch (IOException e) {
+            throw new IllegalArgumentException("Conversion went wrong!");
+        }
+        return this;
+    }
+
+    public List getRequest() throws QueryException {
+        List list = new ArrayList();
+        if (!this.rq.isEmpty())
+            list.addAll(this.rq);
+        System.out.println("RAW QUERY " + this.builder.toString());
+        CollectionQueryTree tree = new CollectionQueryTree(this.verbose);
+        tree.process(this.builder.toString());
+        list.add(tree.getRequestMap());
+        return list;
+    }
+
+    public String toJSON() throws QueryException {
+        return JsonUtils.toJSON(getRequest());
+    }
+
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
index 330b01a..59f4c0d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
@@ -16,8 +16,18 @@
 public class CollectionQueryTree extends Antlr4AbstractSyntaxTree {
 
     private Parser parser;
-    private boolean verbose = false;
+    private boolean verbose;
     private List<ParseTree> visited = new ArrayList<ParseTree>();
+
+
+    public CollectionQueryTree() {
+        verbose = false;
+    }
+
+    public CollectionQueryTree(boolean verbose) {
+        this.verbose = verbose;
+    }
+
     /**
      * Keeps track of active object.
      */
@@ -31,10 +41,6 @@
      */
     LinkedList<Integer> objectsToPop = new LinkedList<Integer>();
     Integer stackedObjects = 0;
-
-    public CollectionQueryTree() {
-    	super();
-	}
     
     public CollectionQueryTree(String query) throws QueryException {
 		process(query);
@@ -58,6 +64,7 @@
         String nodeCat = getNodeCat(node);
         openNodeCats.push(nodeCat);
 
+
         stackedObjects = 0;
 
         if (verbose) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
index 0e41a76..d30fd6d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
@@ -51,7 +51,7 @@
         if (context.startsWith("s") | context.startsWith("p"))
             this.spanContext = new SpanContext(context);
         else {
-            String[] ct = context.split(",");
+            String[] ct = context.replaceAll("\\s+","").split(",");
             String[] lc = ct[0].split("-");
             String[] rc = ct[1].split("-");
             this.spanContext = new SpanContext(Integer.valueOf(lc[0]), lc[1], Integer.valueOf(rc[0]), rc[1]);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index af5d8d8..f0ae995 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -9,6 +9,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -21,7 +22,7 @@
 
     private AbstractSyntaxTree ast;
     private Object collection;
-    private Object meta;
+    private Map meta;
     private org.slf4j.Logger log = LoggerFactory
             .getLogger(QuerySerializer.class);
 
@@ -41,9 +42,8 @@
             queries = new String[]{
 
             };
-        } else {
+        } else
             queries = new String[]{args[0]};
-        }
 
         for (String q : queries) {
             i++;
@@ -143,16 +143,23 @@
     }
 
     private Map raw() {
-        Map<String, Object> requestMap = ast.getRequestMap();
-        if (collection != null)
-            requestMap.put("collections", collection);
-        if (meta != null)
-            requestMap.put("meta", meta);
-        return requestMap;
+        if (ast != null) {
+            Map<String, Object> requestMap = ast.getRequestMap();
+            Map meta = (Map) requestMap.get("meta");
+            if (collection != null)
+                requestMap.put("collections", collection);
+            if (this.meta != null) {
+                meta.putAll(this.meta);
+                requestMap.put("meta", meta);
+            }
+
+            return requestMap;
+        }
+        return new HashMap<>();
     }
 
 
-    public QuerySerializer setMeta(
+    public QuerySerializer addMeta(
             String cli, String cri, int cls, int crs,
             int num, int pageIndex) {
         MetaQueryBuilder meta = new MetaQueryBuilder();
@@ -163,15 +170,16 @@
         return this;
     }
 
-    public QuerySerializer setMeta(String context, int num, int pageidx) {
+    public QuerySerializer addMeta(String context, int num, int pageidx) {
         MetaQueryBuilder meta = new MetaQueryBuilder();
         meta.addEntry("startIndex", pageidx);
         meta.addEntry("count", num);
         meta.setSpanContext(context);
+        this.meta = meta.raw();
         return this;
     }
 
-    public QuerySerializer setMeta(MetaQueryBuilder meta) {
+    public QuerySerializer addMeta(MetaQueryBuilder meta) {
         this.meta = meta.raw();
         return this;
     }
diff --git a/src/test/java/CollectionQueryTreeTest.java b/src/test/java/CollectionQueryTreeTest.java
index 1dd488b..ebe9cc7 100644
--- a/src/test/java/CollectionQueryTreeTest.java
+++ b/src/test/java/CollectionQueryTreeTest.java
@@ -61,7 +61,8 @@
 		map = cqt.getRequestMap().get("collection").toString();
 		assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
 	}
-	
+
+    //todo year type is not yet serialized!
 	@Test
 	public void testThreeConjuncts() throws QueryException {
 		query = "textClass=Sport & year=2014 & corpusID=WPD";
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index d3caaad..93cca72 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -43,7 +43,7 @@
         System.out.println(query.toJSON());
     }
 
-    @Test
+//    @Test
     public void testDates() throws IOException {
         StringBuffer b = new StringBuffer();
         b.append("pubDate:>2013-04-01");
@@ -58,7 +58,7 @@
 //        System.out.println();
     }
 
-    @Test
+//    @Test
     public void testUntil() throws IOException {
         StringBuffer b = new StringBuffer();
         b.append("pubDate:>2013-12-10");
@@ -71,7 +71,7 @@
 //        System.out.println();
     }
 
-    @Test
+//    @Test
     public void testSince() throws IOException {
         StringBuffer b = new StringBuffer();
         b.append("pubDate:<2013-12-10");
@@ -85,7 +85,20 @@
         Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Kafka\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"since\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.toJSON());
     }
 
+
     @Test
+    public void testMeta() {
+        QuerySerializer s = new QuerySerializer();
+        try {
+            s.setQuery("shrink({[base=foo]})", "poliqarp");
+            s.addMeta("2-token, 2-token", 10, 0);
+        } catch (QueryException e) {
+            e.printStackTrace();
+        }
+        System.out.println("THE RESULTING QUERY: " + s.toJSON());
+    }
+
+    //    @Test
     public void testGenerator() throws QueryException {
          /*
          * just for testing...