Only use MaxXxx cut-off if the option setting is non-zero

Fixes #70. Thanks to Damian Gryski for diagnosing the problem.

Change-Id: Ief69c032f12bf9ee44331c77c437b410e34089c3
diff --git a/eval.go b/eval.go
index 7ab81a9..7f2cd6c 100644
--- a/eval.go
+++ b/eval.go
@@ -153,8 +153,8 @@
 		}
 		lastDoc = int(nextDoc)
 
-		if canceled || res.Stats.MatchCount >= opts.ShardMaxMatchCount ||
-			importantMatchCount >= opts.ShardMaxImportantMatch {
+		if canceled || (res.Stats.MatchCount >= opts.ShardMaxMatchCount && opts.ShardMaxMatchCount > 0) ||
+			(opts.ShardMaxImportantMatch > 0 && importantMatchCount >= opts.ShardMaxImportantMatch) {
 			res.Stats.FilesSkipped += d.repoListEntry.Stats.Documents - lastDoc
 			break
 		}
diff --git a/shards/shards.go b/shards/shards.go
index 498f92d..73fd183 100644
--- a/shards/shards.go
+++ b/shards/shards.go
@@ -189,7 +189,7 @@
 			}
 		}
 
-		if cancel != nil && aggregate.Stats.MatchCount > opts.TotalMaxMatchCount {
+		if cancel != nil && opts.TotalMaxMatchCount > 0 && aggregate.Stats.MatchCount > opts.TotalMaxMatchCount {
 			cancel()
 			cancel = nil
 		}
diff --git a/shards/shards_test.go b/shards/shards_test.go
index 9f1b629..27993cc 100644
--- a/shards/shards_test.go
+++ b/shards/shards_test.go
@@ -123,6 +123,12 @@
 			})
 	}
 
+	if res, err := ss.Search(context.Background(), &query.Substring{Pattern: "bla"}, &zoekt.SearchOptions{}); err != nil {
+		t.Errorf("Search: %v", err)
+	} else if len(res.Files) != n {
+		t.Fatalf("empty options: got %d results, want %d", len(res.Files), n)
+	}
+
 	opts := zoekt.SearchOptions{
 		TotalMaxMatchCount: 3,
 	}