Return json request on response
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndexer.java b/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
index 1bdfb8d..b935db8 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndexer.java
@@ -12,25 +12,22 @@
     int count;
     int commitCount;
 
+    // Init logger
     private final static Logger log = LoggerFactory.getLogger(KorapIndexer.class);
 
-    public KorapIndexer () throws IOException {
+    public KorapIndexer(Properties prop) throws IOException {
+        this.indexDir = prop.getProperty("lucene.indexDir");
 
-        Properties prop = new Properties();
-
-	ClassLoader classLoader = getClass().getClassLoader();
-	InputStream fr = classLoader.getResourceAsStream("korap.conf");
-
-	prop.load(fr);
-
-	this.indexDir = prop.getProperty("lucene.index");
-	String commitCount = prop.getProperty("lucene.index.commit.count", "1000");
+	System.out.println("Index to " + this.indexDir);
+	
+        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);
+        this.count = 0;
+        this.commitCount = Integer.parseInt(commitCount);
     };
 
+    
     public void parse (File dir) {
 	for (String file : dir.list()) {
 	    if (file.matches("^[^\\.].+?\\.json\\.gz$")) {
@@ -49,6 +46,7 @@
 	};
     };
 
+
     public void commit () {
 	System.out.println("-----");
 	System.out.print("  Commit ... ");
@@ -61,25 +59,28 @@
 	System.out.println("done.");
     };
 
-    public static void main(String[] args) throws IOException {
 
-	KorapIndexer ki = new KorapIndexer();
 
+    public static void main (String[] argv) throws IOException {
+	Properties prop = new Properties();
+	InputStream fr = new FileInputStream(argv[0]);
+	prop.load(fr);
+	KorapIndexer ki = new KorapIndexer(prop);
 	System.out.println();
 
-	for (String arg : args) {
-	    File f = new File( arg );
-	    if (f.isDirectory()) {
-		ki.parse(f);
-	    };
-	};
+        for (String arg :  Arrays.copyOfRange(argv, 1, argv.length)) {
+            File f = new File(arg);
+            if (f.isDirectory())
+                ki.parse(f);
+        };
 
-	// Final commit
-	ki.commit();
 
-	// Finish indexing
-	System.out.println("-----");
-	System.out.println("  Indexed " + ki.count + " files.");
-	System.out.println();
+        // Final commit
+        ki.commit();
+
+        // Finish indexing
+        System.out.println("-----");
+        System.out.println("  Indexed " + ki.count + " files.");
+        System.out.println();
     };
-};
\ No newline at end of file
+};
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 6b05e36..4c22cd7 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -38,6 +38,8 @@
 	           benchmarkHitCounter = "0";
     private String error = null;
 
+    private JsonNode request;
+
     // Logger
     // This is KorapMatch instead of KorapResult!
     private final static Logger log = LoggerFactory.getLogger(KorapMatch.class);
@@ -129,6 +131,14 @@
 	this.error = msg;
     };
 
+    public void setRequest (JsonNode request) {
+	this.request = request;
+    };
+
+    public JsonNode getRequest () {
+	return this.request;
+    };
+
     public void setBenchmarkSearchResults (long t1, long t2) {
 	this.benchmarkSearchResults = (t2 - t1) * 1e-6 + " ms";
     };
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
index 30895fe..8843e31 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
@@ -34,6 +34,8 @@
     private KorapIndex index;
     private String error;
 
+    private JsonNode request;
+
     public KorapSearchContext leftContext, rightContext;
 
     {
@@ -99,12 +101,12 @@
     public KorapSearch (String jsonString) {
 	ObjectMapper mapper = new ObjectMapper();
 	try {
-	    JsonNode json = mapper.readValue(jsonString, JsonNode.class);
-
+	    this.request = mapper.readValue(jsonString, JsonNode.class);
+	    
 	    // "query" value
-	    if (json.has("query")) {
+	    if (this.request.has("query")) {
 		try {
-		    this.query = new KorapQuery("tokens").fromJSON(json.get("query")).toQuery();
+		    this.query = new KorapQuery("tokens").fromJSON(this.request.get("query")).toQuery();
 		}
 		catch (QueryException q) {
 		    this.error = q.getMessage();
@@ -115,12 +117,12 @@
 	    };
 
 	    // "meta" virtual collections
-	    if (json.has("collections"))
+	    if (this.request.has("collections"))
 		this.setCollection(new KorapCollection(jsonString));
 
 	    if (this.error == null) {
-		if (json.has("meta")) {
-		    JsonNode meta = json.get("meta");
+		if (this.request.has("meta")) {
+		    JsonNode meta = this.request.get("meta");
 
 		    // Defined count
 		    if (meta.has("count"))
@@ -178,6 +180,10 @@
 	return this.query;
     };
 
+    public JsonNode getRequest () {
+	return this.request;
+    };
+
     public KorapSearch setQuery (SpanQueryWrapperInterface sqwi) {
 	this.query = sqwi.toQuery();
 	return this;
@@ -274,6 +280,7 @@
     public KorapResult run (KorapIndex ki) {
 	if (this.query == null) {
 	    KorapResult kr = new KorapResult();
+	    kr.setRequest(this.request);
 	    if (this.error != null)
 		kr.setError(this.error);
 	    else
@@ -283,11 +290,14 @@
 
 	if (this.error != null) {
 	    KorapResult kr = new KorapResult();
+	    kr.setRequest(this.request);
 	    kr.setError(this.error);
 	    return kr;
 	};
 
 	this.getCollection().setIndex(ki);
-	return ki.search(this.getCollection(), this);
+	KorapResult kr = ki.search(this.getCollection(), this);
+	kr.setRequest(this.request);
+	return kr;
     };
 };
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java
new file mode 100644
index 0000000..e7d11a3
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkElementSpans.java
@@ -0,0 +1,131 @@
+package de.ids_mannheim.korap.benchmark;
+
+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.KorapSearch;
+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 de.ids_mannheim.korap.query.wrap.SpanQueryWrapperInterface;
+import de.ids_mannheim.korap.util.QueryException;
+
+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 TestBenchmarkElementSpans {
+
+    @Test
+    public void checkspans1 () throws IOException {
+	Properties prop = new Properties();
+	InputStream fr = new FileInputStream(getClass().getResource("/korap.conf").getFile());
+	prop.load(fr);
+
+	// Get the real index
+	KorapIndex ki = new KorapIndex(new MMapDirectory(new File(prop.getProperty("lucene.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"));
+
+
+	// Create a query
+	// KorapQuery kq = new KorapQuery("tokens");
+
+	long t1 = 0, t2 = 0;
+	t1 = System.nanoTime();
+
+	String json = getString(getClass().getResource("/queries/bsp19.jsonld").getFile());
+
+	int rounds = 1;
+
+	for (int i = 1; i <= rounds; i++) {
+	    /*
+	    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();
+	    */
+	    // SpanQuery query = kq.tag("s").toQuery();
+
+	    KorapResult kr = new KorapSearch(json).run(ki);
+	    System.err.println(kr.toJSON());
+	};
+
+	t2 = System.nanoTime();
+	
+	System.out.println("It took " + ((t2 - t1) / rounds) * 1e-6 + " ms per query");
+
+
+
+	//	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A00\"}},{\"@type\":\"korap:meta-extend\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A01\"}}]}");
+
+	//	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"A01\"}}]}");
+	/*
+	kc = new KorapCollection("{\"meta\":[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#textClass\",\"@value\":\"reisen\"}}]}");
+	kc.setIndex(ki);
+
+	System.err.println(kc.getFilter(0).toString());
+	System.err.println(kc.numberOf("documents"));
+
+	*/
+
+	// assertEquals(14, kc.numberOf("documents"));
+    };
+
+    public static String getString (String path) {
+	StringBuilder contentBuilder = new StringBuilder();
+	try {
+	    BufferedReader in = new BufferedReader(new FileReader(path));
+	    String str;
+	    while ((str = in.readLine()) != null) {
+		contentBuilder.append(str);
+	    };
+	    in.close();
+	} catch (IOException e) {
+	    fail(e.getMessage());
+	}
+	return contentBuilder.toString();
+    };
+
+    public static SpanQueryWrapperInterface jsonQuery (String jsonFile) {
+	SpanQueryWrapperInterface sqwi;
+	
+	try {
+	    String json = getString(jsonFile);
+	    sqwi = new KorapQuery("tokens").fromJSON(json);
+	}
+	catch (QueryException e) {
+	    fail(e.getMessage());
+	    sqwi = new KorapQuery("tokens").seg("???");
+	};
+	return sqwi;
+    };
+    
+};
diff --git a/src/test/resources/queries/bsp19.jsonld b/src/test/resources/queries/bsp19.jsonld
new file mode 100644
index 0000000..5710602
--- /dev/null
+++ b/src/test/resources/queries/bsp19.jsonld
@@ -0,0 +1,46 @@
+{
+    "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+    "query" : {
+	"@type" : "korap:group",
+	"operation" : "operation:sequence",
+	"inOrder" : true,
+	"distances" : [ {
+	    "@type" : "korap:distance",
+	    "key" : "w",
+	    "min" : 1,
+	    "max" : 3
+	}, {
+	    "@type" : "korap:distance",
+	    "key" : "s",
+	    "min" : 0,
+	    "max" : 1
+	} ],
+	"operands" : [ {
+	    "@type" : "korap:token",
+	    "wrap" : {
+		"@type" : "korap:term",
+		"key" : "das",
+		"layer" : "orth",
+		"match" : "match:eq"
+	    }
+	}, {
+	    "@type" : "korap:token",
+	    "wrap" : {
+		"@type" : "korap:term",
+		"key" : "Buch",
+		"layer" : "orth",
+		"match" : "match:eq"
+	    }
+	}
+		     ]
+    },
+    "meta" : {
+	"count":25,
+	"cutOff":true,
+	"context":{
+	    "left":["char",110],
+	    "right":["char",110]
+	},
+	"startPage":1
+    }
+}