Work around empty spanOr queries in class queries

Change-Id: Ie7f28bb5f874e9ecc56622dd6bf766006faefb71
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 4a82670..ffc2b5a 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -1359,7 +1359,7 @@
 
                 final PositionsToOffset pto = new PositionsToOffset(atomic,
                         field);
-
+				
                 // Spans spans = NearSpansOrdered();
                 final Spans spans = query.getSpans(atomic, (Bits) bitset,
                         termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
index 946d75d..3c25751 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
@@ -9,6 +9,7 @@
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
@@ -58,6 +59,16 @@
 
         if (query != this.firstClause) {
 
+			// Rewritten spanquery is empty
+			if (query.getField() == null) {
+
+				// Return an artificially created null-query
+				// I guess there's a better way, but who knows
+				return new SpanTermQuery(
+					new Term(this.firstClause.getField(), "")
+					);
+			};
+
 			SpanClassQuery clone = this.clone();
             clone.firstClause = query;
 			return clone;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
index 5c60938..bbbb955 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSampleIndex.java
@@ -13,6 +13,7 @@
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
 import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanOrQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.store.MMapDirectory;
 import org.junit.BeforeClass;
@@ -267,6 +268,11 @@
         //spans(spanOr([tokens:s:meinem, tokens:s:meinen, tokens:s:meiner, tokens:s:meines]))@0:36-37
     }
 
+	@Test
+	public void testEmptySpanOrQuery () {
+		SpanQuery sq = new SpanOrQuery();
+	};
+
 
     @Test
     public void testWildcardPlusWithCollection () throws IOException {
@@ -284,15 +290,16 @@
         
         // mein+ /+w1:2,s0 &Erfahrung
         SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(
-                new WildcardQuery(new Term("tokens", "s:mein+")));
-        SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(
-                new SpanClassQuery(mtq, (byte) 129),
-                new SpanClassQuery(sq, (byte) 129), constraints, true, true);
+			new WildcardQuery(new Term("tokens", "s:mein+")));
+
+		SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(
+			new SpanClassQuery(mtq, (byte) 129),
+			new SpanClassQuery(sq, (byte) 129), constraints, true, true);
 
         krillAvailabilityAll.setSpanQuery(mdsq);
         kr = sample.search(krillAvailabilityAll);
-        assertEquals(4, kr.getMatches().size());
-        
-        //spanOr([])
+
+		// As described in http://korap.github.io/Koral/, '+' is not a valid wildcard
+		assertEquals(0, kr.getMatches().size());
     }
 }