Added equals implementation in SimpleSpanQuery for rewriting
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index b7f4081..be9dd32 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -212,6 +212,7 @@
 
 	// Failed to open reader
 	catch (IOException e) {
+		//e.printStackTrace();
 	    log.warn( e.getLocalizedMessage() );
 	};
     };
@@ -1103,8 +1104,8 @@
 	try {
 
 	    // Rewrite query (for regex and wildcard queries)
-	    for (Query rewrittenQuery = query.rewrite(this.reader());
-                 rewrittenQuery != (Query) query;
+	    for ( Query rewrittenQuery = query.rewrite(this.reader());
+                 !rewrittenQuery.equals(query);
                  rewrittenQuery = query.rewrite(this.reader())) {
 		query = (SpanQuery) rewrittenQuery;
 	    };
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 5f0dd9d..a9eed77 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SimpleSpanQuery.java
@@ -164,6 +164,47 @@
 		return clone;
 	}
 	
+    /** Used in rewriting query
+     * */
+	@Override
+    public boolean equals (Object o) {
+		if (this == o) return true;
+		if (getClass() != o.getClass()) return false;
+		
+		final SimpleSpanQuery q = (SimpleSpanQuery) o;
+		if (collectPayloads != q.collectPayloads) return false;
+		if (!firstClause.equals(q.firstClause)) return false;
+		if (secondClause != null && 
+				!secondClause.equals(q.secondClause)){ 
+			return false;
+		}
+		else if (clauseList != null){
+			for (int i=0; i < clauseList.size(); i++){
+				SpanQuery query = (SpanQuery) clauseList.get(i);
+				if (!query.equals(q.getClauseList().get(i))) {
+					return false;
+				}
+			}
+		}
+	
+		return true;
+    };
+    
+    public int hashCode() {
+    	int hc = firstClause.hashCode();    	
+    	if (secondClause != null){
+    		hc += secondClause.hashCode();
+    	}    		
+    	else if (clauseList != null){
+    		for (int i=0; i < clauseList.size(); i++){
+				hc += clauseList.get(i).hashCode();
+			}
+    	}
+    	hc ^= (hc << 31) | (hc >>> 3);
+    	hc += Float.floatToRawIntBits(getBoost());
+    	return hc;
+    };
+	
 	public abstract SimpleSpanQuery clone();	
 	
 }