Fixed null field, and null doc in MultipleDistanceSpan.

Change-Id: I59b693f8755681bd0e493c3fc46a14a98a6637e9
diff --git a/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java b/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
index 919022e..a01001c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
@@ -4,6 +4,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.log4j.Logger;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.Query;
@@ -74,6 +75,8 @@
     protected List<SpanQuery> clauseList = null;
     protected String field;
     protected boolean collectPayloads;
+    protected boolean isFieldNull = false;
+    private Logger log = Logger.getLogger(SimpleSpanQuery.class);
 
 
     public SimpleSpanQuery () {}
@@ -98,6 +101,10 @@
                     "The first clause cannot be null.");
         }
         this.field = firstClause.getField();
+        if (field == null){
+            isFieldNull = true;
+            log .warn("Field is null for "+ firstClause.toString());
+        }
         this.setFirstClause(firstClause);
         this.collectPayloads = collectPayloads;
     }
@@ -160,7 +167,12 @@
 
 
     private void checkField (SpanQuery clause) {
-        if (!clause.getField().equals(field)) {
+        String field = clause.getField();
+        if (field == null){
+            log .warn("Field is null for "+ secondClause.toString());
+            isFieldNull = true;
+        }
+        else if (!isFieldNull && !clause.getField().equals(field)) {
             throw new IllegalArgumentException(
                     "Clauses must have the same field.");
         }
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
index 52dc507..edf49c0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
@@ -51,7 +51,9 @@
 
         candidateList = new ArrayList<>();
         candidateListIndex = -1;
-        candidateListDocNum = firstSpans.doc();
+        if (hasMoreFirstSpans){
+            candidateListDocNum = firstSpans.doc();
+        }
     }
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
index 7ff35b2..472583d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRegexWildcardIndex.java
@@ -408,7 +408,9 @@
 			true
 			);
         assertEquals(
-			"spanMultipleDistance(SpanMultiTermQueryWrapper(base:/s:z.*e/), base:s:affe, [(w[1:2], ordered, notExcluded), (base/s:s[0:0], ordered, notExcluded)])",
+			"spanMultipleDistance(SpanMultiTermQueryWrapper(base:/s:z.*e/), "
+			+ "base:s:affe, [(w[1:2], ordered, notExcluded), ("
+			+ "base/s:s[0:0], ordered, notExcluded)])",
 			sq.toString());
         kr = ki.search(new Krill(sq));
         assertEquals((long) 0, kr.getTotalResults());
@@ -422,8 +424,9 @@
 			true
 			);
         assertEquals(
-			"spanMultipleDistance({1: SpanMultiTermQueryWrapper(base:/s:z.*e/)}, base:s:affe, [(w[1:2], ordered, notExcluded), (base/s:s[0:0], ordered, notExcluded)])",
-			sq.toString());
+                "spanMultipleDistance({1: SpanMultiTermQueryWrapper(base:/s:z.*e/)}, "
+                + "base:s:affe, [(w[1:2], ordered, notExcluded), (base/s:s[0:0], ordered, notExcluded)])",
+                sq.toString());
         kr = ki.search(new Krill(sq));
         assertEquals((long) 0, kr.getTotalResults());
     };