Added test regarding missing matches when searching with availability
and non-existing textSigle.

Change-Id: I425870fbd7608fdff7861d8ac008d0d9801ea779
diff --git a/pom.xml b/pom.xml
index 4514523..8115a83 100644
--- a/pom.xml
+++ b/pom.xml
@@ -290,6 +290,7 @@
 						<exclude>**/TestRealIndex.java</exclude>
 						<exclude>**/TestSampleIndex.java</exclude>
 						<exclude>**/TestVCCaching.java</exclude>
+						<exclude>**/TestWithExternalIndex.java</exclude>
 					</excludes>
 				</configuration>
 			</plugin>
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index 3c1b96e..ea0abb3 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -232,8 +232,7 @@
 
             // Filter based on string
             else if (valtype.equals("type:string")) {
-                
-                if (json.get("value").asText().startsWith("[")){
+                if (json.get("value").size() > 1){
                     if (json.has("match")) {
                         match = json.get("match").asText();
                     }
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
index 86c815c..795a6d3 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
@@ -1,5 +1,6 @@
 package de.ids_mannheim.korap.collection;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -8,6 +9,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Paths;
+import java.util.List;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.lucene.store.MMapDirectory;
@@ -17,6 +19,8 @@
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.KrillIndex;
 import de.ids_mannheim.korap.index.FieldDocument;
+import de.ids_mannheim.korap.response.Message;
+import de.ids_mannheim.korap.util.StatusCodes;
 import net.sf.ehcache.Element;
 
 public class TestVCCaching {
@@ -33,6 +37,20 @@
     }
 
     @Test
+    public void testUnknownVC () throws IOException {
+
+        InputStream is = getClass().getClassLoader()
+                .getResourceAsStream("collection/unknown-vc-ref.jsonld");
+        String json = IOUtils.toString(is);
+
+        KrillCollection kc = new KrillCollection(json);
+        List<Message> messages = kc.getErrors().getMessages();
+        assertEquals(1, messages.size());
+
+        assertEquals(StatusCodes.MISSING_COLLECTION, messages.get(0).getCode());
+    }
+    
+    @Test
     public void testCache () throws IOException {
         testManualAddToCache("named-vc/named-vc1.jsonld", "named-vc1");
         testManualAddToCache("named-vc/named-vc2.jsonld", "named-vc2");
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestVCReference.java b/src/test/java/de/ids_mannheim/korap/collection/TestVCReference.java
deleted file mode 100644
index 0a67fa2..0000000
--- a/src/test/java/de/ids_mannheim/korap/collection/TestVCReference.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package de.ids_mannheim.korap.collection;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-import de.ids_mannheim.korap.KrillCollection;
-import de.ids_mannheim.korap.response.Message;
-import de.ids_mannheim.korap.util.StatusCodes;
-
-public class TestVCReference {
-
-    @Test
-    public void testUnknownVC () throws IOException {
-
-        InputStream is = getClass().getClassLoader()
-                .getResourceAsStream("collection/unknown-vc-ref.jsonld");
-        String json = IOUtils.toString(is);
-
-        KrillCollection kc = new KrillCollection(json);
-        List<Message> messages = kc.getErrors().getMessages();
-        assertEquals(1, messages.size());
-
-        assertEquals(StatusCodes.MISSING_COLLECTION, messages.get(0).getCode());
-    }
-}
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestWithExternalIndex.java b/src/test/java/de/ids_mannheim/korap/collection/TestWithExternalIndex.java
new file mode 100644
index 0000000..acaf1ed
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestWithExternalIndex.java
@@ -0,0 +1,39 @@
+package de.ids_mannheim.korap.collection;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Paths;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.lucene.store.MMapDirectory;
+import org.junit.Test;
+
+import de.ids_mannheim.korap.Krill;
+import de.ids_mannheim.korap.KrillIndex;
+
+public class TestWithExternalIndex {
+    private KrillIndex getSampleIndex () throws IOException {
+        return new KrillIndex(new MMapDirectory(
+                Paths.get(getClass().getResource("/sample-index").getFile())));
+    }
+
+    private KrillIndex index;
+
+    public TestWithExternalIndex () throws IOException {
+        index = getSampleIndex();
+    }
+
+    @Test
+    public void testIndexTextSigleNe () throws IOException {
+        InputStream is = getClass().getClassLoader()
+                .getResourceAsStream("queries/collections/query-textSigle-ne.jsonld");
+        String json = IOUtils.toString(is);
+
+        Krill k = new Krill(json).apply(index);
+        long totalResults = k.getTotalResults();
+//        System.out.println(k.toJsonString());
+        assertTrue(totalResults > 0);
+    }
+}
diff --git a/src/test/resources/named-vc/named-vc1.jsonld b/src/test/resources/named-vc/named-vc1.jsonld
index 0fddd89..1257134 100644
--- a/src/test/resources/named-vc/named-vc1.jsonld
+++ b/src/test/resources/named-vc/named-vc1.jsonld
@@ -1,5 +1,4 @@
 {"collection": {
-    "name" : "named-vc1",
     "@type": "koral:doc",
     "key": "textSigle",
     "match": "match:ne",
@@ -7,6 +6,5 @@
     "value": [
         "GOE/AGF/00000",
         "GOE/AGA/01784"
-    ],
-    "cache" : "true"
+    ]
 }}
diff --git a/src/test/resources/queries/collections/query-textSigle-ne.jsonld b/src/test/resources/queries/collections/query-textSigle-ne.jsonld
new file mode 100644
index 0000000..1bf53d3
--- /dev/null
+++ b/src/test/resources/queries/collections/query-textSigle-ne.jsonld
@@ -0,0 +1,31 @@
+{
+    "query": {
+        "@type": "koral:token",
+        "wrap": {
+            "@type": "koral:term",
+            "match": "match:eq",
+            "key": "der",
+            "layer": "orth",
+            "foundry": "opennlp"
+        }
+    },
+    "collection": {
+        "@type": "koral:docGroup",
+        "operation": "operation:and",
+        "operands": [
+            {
+                "@type": "koral:doc",
+                "match": "match:eq",
+                "type": "type:regex",
+                "value": "CC-BY.*",
+                "key": "availability"
+            },
+            {
+                "@type": "koral:doc",
+                "match": "match:ne",
+                "value": "GOE/AGI/00000",
+                "key": "textSigle"
+            }
+        ]
+    }
+}
diff --git a/vc/named-vc1.jsonld b/vc/named-vc1.jsonld
index 0fddd89..1257134 100644
--- a/vc/named-vc1.jsonld
+++ b/vc/named-vc1.jsonld
@@ -1,5 +1,4 @@
 {"collection": {
-    "name" : "named-vc1",
     "@type": "koral:doc",
     "key": "textSigle",
     "match": "match:ne",
@@ -7,6 +6,5 @@
     "value": [
         "GOE/AGF/00000",
         "GOE/AGA/01784"
-    ],
-    "cache" : "true"
+    ]
 }}