Minor bugfix regarding failed search results (buggy serializations)
diff --git a/CHANGES b/CHANGES
index 7b78b91..2e728e6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+0.31.3 2014-06-11
+        - [bugfix] Minor bugfix regarding treatment of
+	  failed search results (diewald)
+
 0.31.2 2014-05-28
         - [feature] Request parameter "itemsPerResource" limits
 	  hits per document (diewald)
diff --git a/pom.xml b/pom.xml
index 2296fe1..4279517 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
 -->
   <groupId>KorAP-modules</groupId>
   <artifactId>KorAP-lucene-index</artifactId>
-  <version>0.31.2</version>
+  <version>0.31.3</version>
   <packaging>jar</packaging>
 
   <name>KorAP-lucene-index</name>
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index c014620..40bbc37 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -1520,7 +1520,8 @@
 	if (json.size() == 0)
 	    return "{}";
 
-	json.put("context", this.getContext().toJSON());
+	if (this.context != null)
+	    json.put("context", this.getContext().toJSON());
 
 	if (this.version != null)
 	    json.put("version", this.getVersion());
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 062e9a8..4cf2ff8 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -235,7 +235,8 @@
     public String toJSON() {
         ObjectNode json = (ObjectNode) mapper.valueToTree(this);
 
-        json.put("context", this.getContext().toJSON());
+	if (this.context != null)
+	    json.put("context", this.getContext().toJSON());
 
 	if (this.itemsPerResource > 0)
 	    json.put("itemsPerResource", this.itemsPerResource);
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
index 023ad9a..c06592d 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -471,6 +471,26 @@
 
 
     @Test
+    public void searchJSONbug () throws IOException {
+
+	// Construct index
+	KorapIndex ki = new KorapIndex();
+	// Indexing test files
+	for (String i : new String[] {"00001", "00002", "00003", "00004", "00005", "00006", "02439"}) {
+	    ki.addDocFile(
+	      getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
+            );
+	};
+	ki.commit();
+
+	String json = getString(getClass().getResource("/queries/bsp-bug.jsonld").getFile());
+
+	KorapResult kr = new KorapSearch(json).run(ki);
+	assertEquals(kr.getError(), "Operation needs exactly two operands");
+    };
+
+
+    @Test
     public void getFoundryDistribution () throws Exception {
 
 	// Construct index
diff --git a/src/test/resources/queries/bsp-bug.jsonld b/src/test/resources/queries/bsp-bug.jsonld
new file mode 100644
index 0000000..33bb904
--- /dev/null
+++ b/src/test/resources/queries/bsp-bug.jsonld
@@ -0,0 +1,15 @@
+{
+  "@context": "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+  "query": {
+    "@type": "korap:group",
+    "operation" : "operation:submatch",
+    "classRef" : [0],
+    "operands" : []
+  },
+  "meta":{
+    "context":{
+      "left":["char",90],
+      "right":["char",90]
+    }
+  }  
+}