Real index test [broken]
diff --git a/src/main/java/de/ids_mannheim/korap/KorapCollection.java b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
index 97e61d6..422a97a 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
@@ -78,9 +78,10 @@
 	return this.filter;
     };
 
+    // Todo: Create new KorapSearch Object!
 
     public KorapResult search (SpanQuery query) {
-	return this.index.search(this, query, 0, (short) 5, true, (short) 5, true, (short) 5);
+	return this.index.search(this, query, 17, (short) 20, true, (short) 5, true, (short) 5);
     };
 
     public FixedBitSet bits (AtomicReaderContext atomic) throws IOException  {
@@ -100,11 +101,16 @@
 
 	    ArrayList<FilterOperation> filters = (ArrayList<FilterOperation>) this.filter.clone();
 
+	    FilterOperation kcInit = filters.remove(0);
+	    log.trace("FILTER: {}", kcInit);
+
+
 	    // Init vector
-	    DocIdSet docids = filters.remove(0).filter.getDocIdSet(atomic, null);
+	    DocIdSet docids = kcInit.filter.getDocIdSet(atomic, null);
 	    DocIdSetIterator filterIter = docids.iterator();
 
 	    if (filterIter != null) {
+		log.trace("InitFilter has effect");
 		bitset.or(filterIter);
 		noDoc = false;
 	    };
diff --git a/src/main/java/de/ids_mannheim/korap/KorapFilter.java b/src/main/java/de/ids_mannheim/korap/KorapFilter.java
index 843f618..33ebc73 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapFilter.java
@@ -21,22 +21,6 @@
  */
 
 /*
-<request>
-  <query>
-    ...XYZ...
-  </query>
-  <filter>
-    <cond><foundry value="Treetagger" /></cond>
-    <cond><foundry value="MATE" /></cond>
-    <condOr>
-      <cond><textClass value="sports" /></cond>
-      <cond><textClass value="news" /></cond>
-    </condOr>
-    <cond><pubDate till="2009" /></cond>
-    <cond><author regex="Peter .+?" /></cond>
-  </filter>
-</request>
-
 Suche XYZ in allen Documenten in den Foundries "Treetagger" und "MATE", die entweder den Texttyp "sports" oder den Texttyp "news" haben, bis höchsten 2009 publiziert wurden und deren Autor auf den regulären Ausdruck "Peter .+?" matcht.
 
 textClass
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 58d90ca..fc0d31c 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -477,6 +477,8 @@
 			       short rightContext) {
 
 
+	log.trace("Start search");
+
 	this.termContexts = new HashMap<Term, TermContext>();
 	String foundry = query.getField();
 
@@ -494,8 +496,15 @@
 	fieldsToLoadLocal.add(foundry);
 
 	try {
+	    int i = 0;
+	    long t1 = 0;
+	    long t2 = 0;
+
+	    ArrayList<KorapMatch> atomicMatches = new ArrayList<KorapMatch>(kr.itemsPerPage());
+
 	    for (AtomicReaderContext atomic : this.reader().leaves()) {
 
+		log.trace("NUKULAR!");
 
 		// Use OpenBitSet;
 		Bits bitset = collection.bits(atomic);
@@ -510,11 +519,12 @@
 		// TODO: Get document information from Cache!
 
 		// See: http://www.ibm.com/developerworks/java/library/j-benchmark1/index.html
-		long t1 = System.nanoTime();
+		t1 = System.nanoTime();
 
-		int i = 0;
 		for (; i < kr.itemsPerPage(); i++) {
 
+		    log.trace("Match Nr {}/{}", i, count);
+
 		    if (spans.next() != true) {
 			break;
 		    };
@@ -525,7 +535,8 @@
 		    int localDocID = spans.doc();
 		    int docID = atomic.docBase + localDocID;
 
-		    Document doc = lreader.document(docID, fieldsToLoadLocal);
+		    // Document doc = lreader.document(docID, fieldsToLoadLocal);
+		    Document doc = lreader.document(localDocID, fieldsToLoadLocal);
 		    KorapMatch match = new KorapMatch();
 
 		    match.startPos = spans.start();
@@ -643,6 +654,8 @@
 		    match.setCorpusID(doc.get("corpusID"));
 		    match.setPubDate(doc.get("pubDate"));
 
+		    log.trace("I've got a match in {} of {}", match.getID(), count);
+
 		    // Temporary (later meta fields in term vector)
 		    match.setFoundries(doc.get("foundries"));
 		    match.setTokenization(doc.get("tokenization"));
@@ -650,27 +663,35 @@
 		    match.setPrimaryData(
 		      new KorapPrimaryData(doc.get(foundry))
 		    );
-
+		    atomicMatches.add(match);
 		    kr.add(match);
 		};
 
-		long t2 = System.nanoTime();
+		// Benchmark till now
+		if (i >= kr.itemsPerPage() &&
+		    kr.getBenchmarkSearchResults().length() == 0) {
+		    t2 = System.nanoTime();
+		    kr.setBenchmarkSearchResults(t1, t2);
+		};
 
-		kr.setBenchmarkSearchResults(t1, t2);
-
-		while (spans.next() == true) {
+		while (spans.next()) {
 		    i++;
 		};
 
-		kr.setBenchmarkHitCounter(t2, System.nanoTime());
-
-		kr.setTotalResults(i);
-
-		for (KorapMatch km : kr.getMatches()) {
+		for (KorapMatch km : atomicMatches) {
 		    km.processHighlight(pto);
 		};
+		atomicMatches.clear();
 	    };
 
+	    t1 = System.nanoTime();
+	    kr.setBenchmarkHitCounter(t2, t1);
+	    if (kr.getBenchmarkSearchResults().length() == 0) {
+		kr.setBenchmarkSearchResults(t2, t1);
+	    };
+	    kr.setTotalResults(i);
+
+
 	    // if (spans.isPayloadAvailable()) {
 	    // for (byte[] payload : spans.getPayload()) {
 	    // // retrieve payload for current matching span
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndexer.java b/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
index d6361fe..cf9355b 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
@@ -3,14 +3,29 @@
 import java.io.*;
 import org.apache.lucene.store.MMapDirectory;
 import de.ids_mannheim.korap.KorapIndex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class KorapIndexer {
     KorapIndex index;
+    String indexDir;
     int count;
+    int commitCount;
+
+    private final static Logger log = LoggerFactory.getLogger(KorapIndexer.class);
 
     public KorapIndexer () throws IOException {
-	this.index = new KorapIndex(new MMapDirectory(new File("target/test/")));
+
+        Properties prop = new Properties();
+	FileReader fr = new FileReader(getClass().getResource("/korap.conf").getFile());
+	prop.load(fr);
+
+	this.indexDir = prop.getProperty("lucene.index");
+	String commitCount = prop.getProperty("lucene.index.commit.count", "1000");
+
+	this.index = new KorapIndex(new MMapDirectory(new File(indexDir)));
 	this.count = 0;
+	this.commitCount = Integer.parseInt(commitCount);
     };
 
     public void parse (File dir) {
@@ -25,12 +40,27 @@
 		    System.out.println("fail.");
 		    continue;
 		};
-		System.out.println("done.");
+		System.out.println("done (" + count + ").");
 		this.count++;
+
+		if ((this.count % this.commitCount) == 0)
+		    this.commit();
 	    };
 	};
     };
 
+    public void commit () {
+	System.out.println("-----");
+	System.out.print("  Commit ... ");
+	try {
+	    this.index.commit();
+	}
+	catch (IOException e) {
+	    System.err.println("Unable to commit to index " + this.indexDir);
+	};
+	System.out.println("done.");
+    };
+
     public static void main(String[] args) throws IOException {
 
 	KorapIndexer ki = new KorapIndexer();
@@ -44,10 +74,10 @@
 	    };
 	};
 
-	System.out.println("-----");
-	System.out.print("  Commit ... ");
-	ki.index.commit();
-	System.out.println("done.");
+	// Final commit
+	ki.commit();
+
+	// Finish indexing
 	System.out.println("-----");
 	System.out.println("  Indexed " + ki.count + " files.");
 	System.out.println();
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index 6d9bb68..8d56f83 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -503,7 +503,7 @@
 	// right context
 	if (rightTokenContext) {
 	    endOffsetChar = pto.end(ldid, this.endPos + this.rightContext - 1);
-	    log.trace("For endOffset {} pto returns {}", (this.endPos + this.rightContext - 1), endOffsetChar);
+	    log.trace("For endOffset {} ({}+{}-1) pto returns {}", (this.endPos + this.rightContext - 1), this.endPos, this.rightContext, endOffsetChar);
 	}
 	else {
 	    if (endPosChar == -1) {
@@ -542,7 +542,7 @@
 	    endMore = false;
 	};
 
-	log.trace("Temporary snippet is {}", this.tempSnippet);
+	log.trace("Temporary snippet is \"{}\"", this.tempSnippet);
 
         LinkedList<int[]> spans = new LinkedList<int[]>();
 
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 0e5184f..22a66bb 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -31,6 +31,7 @@
     private String error = null;
 
     // Logger
+    // This is KorapMatch instead of KorapResult!
     private final static Logger log = LoggerFactory.getLogger(KorapMatch.class);
 
     public KorapResult (String query,
diff --git a/src/main/resources/korap.conf b/src/main/resources/korap.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/main/resources/korap.conf
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index 51e0403..0b4991c 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,6 +1,6 @@
 ## logger file can be used with
 
-log4j.rootLogger = DEBUG, stdout
+# log4j.rootLogger = DEBUG, stdout
 
 #log4j.logger.de.ids_mannheim.korap.query.spans.ElementSpans = TRACE, stdout
 #log4j.logger.de.ids_mannheim.korap.query.spans.WithinSpans = TRACE, stdout
@@ -9,8 +9,10 @@
 #log4j.logger.de.ids_mannheim.korap.query.spans.KorapTermSpan = TRACE, stdout
 #log4j.logger.de.ids_mannheim.korap.query.spans.ClassSpans = TRACE, stdout
 #log4j.logger.de.ids_mannheim.korap.query.spans.MatchSpans = TRACE, stdout
-#log4j.logger.de.ids_mannheim.korap.KorapIndex = TRACE, stdout
-#log4j.logger.de.ids_mannheim.korap.KorapMatch = TRACE, stdout
+log4j.logger.de.ids_mannheim.korap.KorapIndex = TRACE, stdout
+log4j.logger.de.ids_mannheim.korap.KorapMatch = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.KorapCollection = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.index.PositionsToOffset = TRACE, stdout
 
 # log4j.logger.de.ids_mannheim.korap.analysis.MultiTermTokenStream = TRACE, stdout
 
diff --git a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
index 2e557b4..ea35a63 100644
--- a/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
+++ b/src/test/java/de/ids_mannheim/korap/filter/TestKorapCollection.java
@@ -52,6 +52,13 @@
 	assertEquals("Sentences", 75, kc.numberOf("sentences"));
 	assertEquals("Paragraphs", 48, kc.numberOf("paragraphs"));
 
+	kc.filter(kf.and("corpusID", "WPD"));
+
+	assertEquals("Documents", 1, kc.numberOf("documents"));
+	assertEquals("Tokens", 405, kc.numberOf("tokens"));
+	assertEquals("Sentences", 75, kc.numberOf("sentences"));
+	assertEquals("Paragraphs", 48, kc.numberOf("paragraphs"));
+
 	// Create a query
 	KorapQuery kq = new KorapQuery("tokens");
 	SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
@@ -67,7 +74,55 @@
 	assertEquals("Tokens", 1669, kc.numberOf("tokens"));
 	assertEquals("Sentences", 188, kc.numberOf("sentences"));
 	assertEquals("Paragraphs", 130, kc.numberOf("paragraphs"));
-	System.err.println(kr.toJSON());
+	// System.err.println(kr.toJSON());
+    };
+
+
+    @Test
+    public void filterExample2 () throws IOException {
+	
+	// Construct index
+	KorapIndex ki = new KorapIndex();
+	FieldDocument fd;
+	// Indexing test files
+	for (String i : new String[] {"00001", "00002", "00003", "00004", "00005", "00006", "02439"}) {
+	    fd = ki.addDocFile(
+	      getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
+            );
+	};
+	ki.commit();
+
+	fd = ki.addDocFile(getClass().getResource("/wiki/AUG-55286.json.gz").getFile(), true);
+
+	ki.commit();
+
+	KorapFilter kf = new KorapFilter();
+
+	// Create Virtual collections:
+	KorapCollection kc = new KorapCollection(ki);
+	kc.filter( kf.and("textClass", "reisen").and("textClass", "freizeit-unterhaltung") );
+	assertEquals("Documents", 6, kc.numberOf("documents"));
+	assertEquals("Tokens", 2089, kc.numberOf("tokens"));
+	assertEquals("Sentences", 234, kc.numberOf("sentences"));
+	assertEquals("Paragraphs", 141, kc.numberOf("paragraphs"));
+
+	kc.filter( kf.and("corpusID", "A00") );
+
+	assertEquals("Documents", 1, kc.numberOf("documents"));
+	assertEquals("Tokens", 411, kc.numberOf("tokens"));
+	assertEquals("Sentences", 40, kc.numberOf("sentences"));
+	assertEquals("Paragraphs", 2, kc.numberOf("paragraphs"));
+
+	//	assertEquals("Documents", 1, kc.numberOf("documents"));
+
+	// Create a query
+	KorapQuery kq = new KorapQuery("tokens");
+	SpanQuery query = kq.seg("opennlp/p:NN").with("tt/p:NN").toQuery();
+
+	KorapResult kr = kc.search(query);
+
+	assertEquals(87, kr.totalResults());
+	// System.out.println(kr.toJSON());
     };
 };
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
new file mode 100644
index 0000000..f7fcac1
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -0,0 +1,74 @@
+import java.util.*;
+import java.io.*;
+
+import de.ids_mannheim.korap.KorapIndex;
+import de.ids_mannheim.korap.index.FieldDocument;
+import de.ids_mannheim.korap.KorapCollection;
+import de.ids_mannheim.korap.KorapFilter;
+import de.ids_mannheim.korap.KorapResult;
+import de.ids_mannheim.korap.KorapQuery;
+import org.apache.lucene.store.MMapDirectory;
+import de.ids_mannheim.korap.filter.BooleanFilter;
+import org.apache.lucene.search.spans.SpanQuery;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class TestRealIndex {
+
+    @Test
+    public void realExample1 () throws IOException {
+
+	// Load configuration file
+	Properties prop = new Properties();
+	FileReader fr = new FileReader(getClass().getResource("/korap.conf").getFile());
+	prop.load(fr);
+
+	// Check if the configuration was loaded fine
+	assertEquals(prop.getProperty("lucene.properties"), "true");
+
+	String indexDir = prop.getProperty("lucene.index");
+
+	// Get the real index
+	KorapIndex ki = new KorapIndex(new MMapDirectory(new File(indexDir)));
+
+	// Create a container for virtual collections:
+	KorapCollection kc = new KorapCollection(ki);
+
+	// Construct filter generator
+	KorapFilter kf = new KorapFilter();
+
+	// The virtual collection consists of all documents that have
+	// the textClasses "reisen" and "freizeit"
+	//	kc.filter( kf.and("textClass", "reisen").and("textClass", "freizeit-unterhaltung") );
+
+	// This is real slow atm - sorry
+	kc.filter(kf.and("textClass", "kultur"));
+	// kc.filter(kf.and("ID", "A00_JAN.02873"));
+
+
+	// Create a query
+	KorapQuery kq = new KorapQuery("tokens");
+
+	SpanQuery query =
+	    kq.within(
+              kq.tag("xip/const:NPA"),
+              kq._(1,
+                kq.seq(
+	          kq._(2, kq.seg("cnx/p:A").with("mate/m:number:sg"))
+                ).append(
+  		  kq.seg("opennlp/p:NN").with("tt/p:NN")
+	        )
+	      )
+            ).toQuery();
+
+
+	KorapResult kr = kc.search(query);
+
+	System.err.println(kr.toJSON());
+    };
+};
\ No newline at end of file
diff --git a/src/test/resources/korap.conf b/src/test/resources/korap.conf
new file mode 100644
index 0000000..555b1a8
--- /dev/null
+++ b/src/test/resources/korap.conf
@@ -0,0 +1,5 @@
+# Lucene Backend properties
+lucene.properties = true
+lucene.index = /home/ndiewald/Repositories/korap/KorAP-modules/KorAP-lucene-index/sandbox/index
+lucene.index.commit.count = 5000
+lucene.index.commit.log = log/korap.commit.log
\ No newline at end of file
diff --git a/src/test/resources/queries/bsp1.json b/src/test/resources/queries/bsp1.json
new file mode 100644
index 0000000..4085309
--- /dev/null
+++ b/src/test/resources/queries/bsp1.json
@@ -0,0 +1,76 @@
+{
+   "@context":{
+      "korap":"http://korap.ids-mannheim.de/ns/query",
+      "@language":"de",
+      "operands":{
+         "@id":"korap:operands",
+         "@container":"@list"
+      },
+      "relation":{
+         "@id":"korap:relation",
+         "@type":"korap:relation#types"
+      },
+      "class":{
+         "@id":"korap:class",
+         "@type":"xsd:integer"
+      },
+      "query":"korap:query",
+      "filter":"korap:filter",
+      "meta":"korap:meta"
+   },
+   "query":{
+      "@type":"korap:group",
+      "relation":"or",
+      "operands":[
+         {
+            "@type":"korap:token",
+            "@value":{
+               "@type":"korap:term",
+               "@value":"base:foo",
+               "relation":"="
+            }
+         },
+         {
+            "@type":"korap:sequence",
+            "operands":[
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:foo",
+                     "relation":"="
+                  }
+               },
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:bar",
+                     "relation":"="
+                  },
+                  "repetition":"*"
+               }
+            ]
+         }
+      ]
+   },
+   "meta":{
+      "@type":"korap:meta",
+      "@value":{
+         "@type":"korap:group",
+         "operands":[
+            {
+               "@type":"korap:term",
+               "@value":"author:Goethe",
+               "relation":"="
+            },
+            {
+               "@type":"korap:term",
+               "@value":"year:1815",
+               "relation":"="
+            }
+         ],
+         "relation":"and"
+      }
+   }
+}
diff --git a/src/test/resources/queries/bsp2.json b/src/test/resources/queries/bsp2.json
new file mode 100644
index 0000000..f97a4fd
--- /dev/null
+++ b/src/test/resources/queries/bsp2.json
@@ -0,0 +1,56 @@
+{
+   "@context":{
+      "korap":"http://korap.ids-mannheim.de/ns/query",
+      "@language":"de",
+      "operands":{
+         "@id":"korap:operands",
+         "@container":"@list"
+      },
+      "relation":{
+         "@id":"korap:relation",
+         "@type":"korap:relation#types"
+      },
+      "class":{
+         "@id":"korap:class",
+         "@type":"xsd:integer"
+      },
+      "query":"korap:query",
+      "filter":"korap:filter",
+      "meta":"korap:meta"
+   },
+   "query":{
+      "@type":"korap:sequence",
+      "operands":[
+         {
+            "@type":"korap:group",
+            "relation":"or",
+            "operands":[
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:foo",
+                     "relation":"="
+                  }
+               },
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:bar",
+                     "relation":"="
+                  }
+               }
+            ]
+         },
+         {
+            "@type":"korap:token",
+            "@value":{
+               "@type":"korap:term",
+               "@value":"base:foobar",
+               "relation":"="
+            }
+         }
+      ]
+   }
+}
diff --git a/src/test/resources/queries/bsp3.json b/src/test/resources/queries/bsp3.json
new file mode 100644
index 0000000..10a9f21
--- /dev/null
+++ b/src/test/resources/queries/bsp3.json
@@ -0,0 +1,41 @@
+{
+   "@context":{
+      "korap":"http://korap.ids-mannheim.de/ns/query",
+      "@language":"de",
+      "operands":{
+         "@id":"korap:operands",
+         "@container":"@list"
+      },
+      "relation":{
+         "@id":"korap:relation",
+         "@type":"korap:relation#types"
+      },
+      "class":{
+         "@id":"korap:class",
+         "@type":"xsd:integer"
+      },
+      "query":"korap:query",
+      "filter":"korap:filter",
+      "meta":"korap:meta"
+   },
+   "query":{
+      "@type":"korap:sequence",
+      "shrink":"0",
+      "operands":[
+         {
+            "@type":"korap:group",
+            "class":"0",
+            "operands":[
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:foo",
+                     "relation":"="
+                  }
+               }
+            ]
+         }
+      ]
+   }
+}
diff --git a/src/test/resources/queries/bsp4.json b/src/test/resources/queries/bsp4.json
new file mode 100644
index 0000000..e98afbd
--- /dev/null
+++ b/src/test/resources/queries/bsp4.json
@@ -0,0 +1,49 @@
+{
+   "@context":{
+      "korap":"http://korap.ids-mannheim.de/ns/query",
+      "@language":"de",
+      "operands":{
+         "@id":"korap:operands",
+         "@container":"@list"
+      },
+      "relation":{
+         "@id":"korap:relation",
+         "@type":"korap:relation#types"
+      },
+      "class":{
+         "@id":"korap:class",
+         "@type":"xsd:integer"
+      },
+      "query":"korap:query",
+      "filter":"korap:filter",
+      "meta":"korap:meta"
+   },
+   "query":{
+      "@type":"korap:sequence",
+      "shrink":"0",
+      "operands":[
+         {
+            "@type":"korap:group",
+            "class":"0",
+            "operands":[
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:foo",
+                     "relation":"="
+                  }
+               }
+            ]
+         },
+         {
+            "@type":"korap:token",
+            "@value":{
+               "@type":"korap:term",
+               "@value":"orth:bar",
+               "relation":"="
+            }
+         }
+      ]
+   }
+}
diff --git a/src/test/resources/queries/bsp5.json b/src/test/resources/queries/bsp5.json
new file mode 100644
index 0000000..246df1e
--- /dev/null
+++ b/src/test/resources/queries/bsp5.json
@@ -0,0 +1,49 @@
+{
+   "@context":{
+      "korap":"http://korap.ids-mannheim.de/ns/query",
+      "@language":"de",
+      "operands":{
+         "@id":"korap:operands",
+         "@container":"@list"
+      },
+      "relation":{
+         "@id":"korap:relation",
+         "@type":"korap:relation#types"
+      },
+      "class":{
+         "@id":"korap:class",
+         "@type":"xsd:integer"
+      },
+      "query":"korap:query",
+      "filter":"korap:filter",
+      "meta":"korap:meta"
+   },
+   "query":{
+      "@type":"korap:sequence",
+      "shrink":"1",
+      "operands":[
+         {
+            "@type":"korap:token",
+            "@value":{
+               "@type":"korap:term",
+               "@value":"base:Der",
+               "relation":"="
+            }
+         },
+         {
+            "@type":"korap:group",
+            "class":"1",
+            "operands":[
+               {
+                  "@type":"korap:token",
+                  "@value":{
+                     "@type":"korap:term",
+                     "@value":"base:Mann",
+                     "relation":"="
+                  }
+               }
+            ]
+         }
+      ]
+   }
+}
diff --git a/src/test/resources/queries/readme.txt b/src/test/resources/queries/readme.txt
new file mode 100644
index 0000000..b82454f
--- /dev/null
+++ b/src/test/resources/queries/readme.txt
@@ -0,0 +1,5 @@
+bsp1.json: [base=foo]|([base=foo][base=bar])* meta author=Goethe&year=1815
+bsp2.json: ([base=foo]|[base=bar])[base=foobar]
+bsp3.json: shrink({[base=Mann]})
+bsp4.json: shrink({[base=foo]}[orth=bar])
+bsp5.json: shrink(1:[base=Der]{1:[base=Mann]})