Updated MatchInfo service.

Change-Id: I0cdbda524190ad2a1b75267eb6882a530adb172d
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
index 7e750f9..6a71682 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
@@ -131,8 +131,7 @@
 
 
     public static SecurityManager findbyPath (String path, User user,
-            Permissions.Permission ... perms) throws NotAuthorizedException,
-            EmptyResultException {
+            Permissions.Permission ... perms) throws KustvaktException {
         SecurityManager manager = new SecurityManager(user);
         manager.findPolicies(path, true, perms);
         //fixme: need a match count. if match not unique, exception. also, does parent -child relation match hold up here?
@@ -141,8 +140,7 @@
 
 
     public static SecurityManager init (String id, User user,
-            Permissions.Permission ... perms) throws NotAuthorizedException,
-            EmptyResultException {
+            Permissions.Permission ... perms) throws KustvaktException  {
         SecurityManager p = new SecurityManager(user);
         p.findPolicies(id, false, perms);
         return p;
@@ -216,7 +214,7 @@
 
     // todo: type should be deprecated and return type of policies should be containers!
     private boolean findPolicies (Object id, boolean path,
-            Permissions.Permission ... perms) throws EmptyResultException {
+            Permissions.Permission ... perms) throws KustvaktException {
         PermissionsBuffer b = new PermissionsBuffer();
         if (perms.length == 0)
             b.addPermission(Permissions.Permission.READ.toByte());
@@ -231,12 +229,14 @@
         if (id instanceof Integer)
             this.policies = policydao.getPolicies((Integer) id, this.user,
                     b.getPbyte());
+        
         this.evaluator = new PolicyEvaluator(this.user, this.policies);
 
         if (this.policies == null) {
             jlog.error("No policies found for resource id '{}' for user '{}'",
                     id, user.getId());
-            throw new EmptyResultException(String.valueOf(id));
+            throw new KustvaktException(StatusCodes.NO_VALUE_FOUND, "Resource not found!",
+                    String.valueOf(id));
         }
         return true;
     }
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index aac0f2f..ab37c80 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -1,21 +1,21 @@
 // Connector to the Lucene Backend
 package de.ids_mannheim.korap.web;
 
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.apache.lucene.store.MMapDirectory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import de.ids_mannheim.korap.Krill;
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.KrillIndex;
 import de.ids_mannheim.korap.response.Match;
 import de.ids_mannheim.korap.response.Result;
 import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.utils.KustvaktLogger;
-import org.apache.lucene.store.MMapDirectory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.nio.file.Paths;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
 
 /**
  * The SearchKrill class allows for searching in the
@@ -24,7 +24,6 @@
  * @author Nils Diewald
  */
 public class SearchKrill {
-    private final static Logger qlog = KustvaktLogger.getLogger("queryLogger");
     private final static Logger jlog = LoggerFactory
             .getLogger(SearchKrill.class);
 
@@ -34,7 +33,6 @@
     String klinux10 = "/vol/work/hanl/indices";
     private KrillIndex index;
 
-
     /**
      * Constructor
      */
@@ -59,7 +57,6 @@
         };
     };
 
-
     public KrillIndex getIndex () {
         return this.index;
     };
@@ -73,7 +70,7 @@
      *            filters.
      */
     public String search (String json) {
-        qlog.trace(json);
+        jlog.trace(json);
         if (this.index != null)
             return new Krill(json).apply(this.index).toJsonString();
         Result kr = new Result();
@@ -91,7 +88,7 @@
      */
     @Deprecated
     public String searchTokenList (String json) {
-        qlog.trace(json);
+        jlog.trace(json);
         if (this.index != null)
             return new Krill(json).apply(this.index).toTokenListJsonString();
         Result kr = new Result();
@@ -203,7 +200,7 @@
      */
     @Deprecated
     public String getStatistics (String json) {
-        qlog.trace(json);
+        jlog.trace(json);
         if (this.index == null) {
             return "{\"documents\" : -1, error\" : \"No index given\" }";
         };
@@ -230,24 +227,19 @@
         return sb.toString();
     };
 
+
     /**
-	 * Return the match identifier as a string.
-	 * This is a convenient method to deal with legacy instantiation of the
-	 * code.
-	 */
-    public String getMatchId (String corpusID, String docID, String matchID) {
-		String docIDtextID [] = docID.split("\\.", 2);
-
-		// Create a string representation of the match 
-		StringBuilder sb = new StringBuilder()
-			.append("match-")
-			.append(corpusID).append('/')
-			.append(docIDtextID[0]);
-
-		// The docID was split
-		if (docIDtextID.length == 2)
-			sb.append('/').append(docIDtextID[1]);
-
-		return sb.append('-').append(matchID).toString();
+     * Return the match identifier as a string.
+     * This is a convenient method to deal with legacy instantiation
+     * of the
+     * code.
+     */
+    public String getMatchId (String corpusID, String docID, String textID,
+            String matchID) {
+        // Create a string representation of the match 
+        StringBuilder sb = new StringBuilder();
+        sb.append("match-").append(corpusID).append('/').append(docID)
+                .append('/').append(textID).append('-').append(matchID);
+        return sb.toString();
     };
 };
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index df35d9b..d7be4e0 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -1030,17 +1030,21 @@
 
     // fixme: only allowed for corpus?!
     @GET
-    @Path("/corpus/{id}/{docid}/{rest}/matchInfo")
+    @Path("/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
     public Response getMatchInfo (@Context SecurityContext ctx,
-            @Context Locale locale, @PathParam("id") String id,
-            @PathParam("docid") String docid, @PathParam("rest") String rest,
+            @Context Locale locale, 
+            @PathParam("corpusId") String corpusId,
+            @PathParam("docId") String docId,
+            @PathParam("textId") String textId, 
+            @PathParam("matchId") String matchId,
             @QueryParam("foundry") Set<String> foundries,
             @QueryParam("layer") Set<String> layers,
-            @QueryParam("spans") Boolean spans) {
+            @QueryParam("spans") Boolean spans) throws KustvaktException {
+        
         TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
         spans = spans != null ? spans : false;
-        String matchid = searchKrill.getMatchId(id, docid, rest);
-
+        
+        String matchid = searchKrill.getMatchId(corpusId, docId, textId, matchId);
         if (layers == null || layers.isEmpty())
             layers = new HashSet<>();
 
@@ -1051,8 +1055,7 @@
             user = controller.getUser(tokenContext.getUsername());
         }
         catch (KustvaktException e) {
-
-            jlog.error("Exception encountered: {}", e.string());
+            jlog.error("Failed getting user in the matchInfo service: {}", e.string());
             throw KustvaktResponseHandler.throwit(e);
         }
 
@@ -1066,7 +1069,7 @@
 
             for (String spl : new ArrayList<>(foundries)) {
                 try {
-                    de.ids_mannheim.korap.security.ac.SecurityManager manager = SecurityManager
+                    SecurityManager<?> manager = SecurityManager
                             .init(spl, user, Permissions.Permission.READ);
                     if (!manager.isAllowed())
                         continue;
@@ -1080,14 +1083,9 @@
                             new ArrayList<>(f_list), new ArrayList<>(l_list),
                             spans, false, true);
                 }
-                catch (EmptyResultException e) {
-                    throw KustvaktResponseHandler.throwit(
-                            StatusCodes.NO_VALUE_FOUND, "Resource not found!",
-                            id);
-                }
                 catch (NotAuthorizedException e) {
                     throw KustvaktResponseHandler.throwit(
-                            StatusCodes.ACCESS_DENIED, "Permission denied", id);
+                            StatusCodes.ACCESS_DENIED, "Permission denied", matchid);
                 }
 
             }
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index 1003e0d..5bb3fa6 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -297,13 +297,15 @@
 	 * "getMatchID()" for a workaround, but this should be fixed.
 	 */
     @GET
-    @Path("/corpus/{id}/{docid}/{rest}/matchInfo")
-    public Response getMatchInfo (@PathParam("id") String id,
-								  @PathParam("docid") String docid, @PathParam("rest") String rest,
+    @Path("/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
+    public Response getMatchInfo (@PathParam("corpusId") String corpusId,
+            @PathParam("docId") String docId,
+            @PathParam("textId") String textId, 
+            @PathParam("matchId") String matchId,
             @QueryParam("foundry") Set<String> foundries,
             @QueryParam("layer") Set<String> layers,
             @QueryParam("spans") Boolean spans) {
-        String matchid = searchKrill.getMatchId(id, docid, rest);
+        String matchid = searchKrill.getMatchId(corpusId, docId, textId, matchId);
         List<String> f_list = null;
         List<String> l_list = null;
         if (layers != null && !layers.isEmpty())
diff --git a/src/main/resources/index-goe-lucene5/_0.cfe b/src/main/resources/index-goe-lucene5/_0.cfe
deleted file mode 100644
index 72246bc..0000000
--- a/src/main/resources/index-goe-lucene5/_0.cfe
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_0.cfs b/src/main/resources/index-goe-lucene5/_0.cfs
deleted file mode 100644
index d15185a..0000000
--- a/src/main/resources/index-goe-lucene5/_0.cfs
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_0.si b/src/main/resources/index-goe-lucene5/_0.si
deleted file mode 100644
index d66ea34..0000000
--- a/src/main/resources/index-goe-lucene5/_0.si
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_1.cfe b/src/main/resources/index-goe-lucene5/_1.cfe
deleted file mode 100644
index 221e372..0000000
--- a/src/main/resources/index-goe-lucene5/_1.cfe
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_1.cfs b/src/main/resources/index-goe-lucene5/_1.cfs
deleted file mode 100644
index 6b998a4..0000000
--- a/src/main/resources/index-goe-lucene5/_1.cfs
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_1.si b/src/main/resources/index-goe-lucene5/_1.si
deleted file mode 100644
index 18b647a..0000000
--- a/src/main/resources/index-goe-lucene5/_1.si
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_2.cfe b/src/main/resources/index-goe-lucene5/_2.cfe
deleted file mode 100644
index 0b8386b..0000000
--- a/src/main/resources/index-goe-lucene5/_2.cfe
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_2.cfs b/src/main/resources/index-goe-lucene5/_2.cfs
deleted file mode 100644
index f9828fd..0000000
--- a/src/main/resources/index-goe-lucene5/_2.cfs
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_2.si b/src/main/resources/index-goe-lucene5/_2.si
deleted file mode 100644
index ddcd167..0000000
--- a/src/main/resources/index-goe-lucene5/_2.si
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_3.cfe b/src/main/resources/index-goe-lucene5/_3.cfe
deleted file mode 100644
index 2eaa97b..0000000
--- a/src/main/resources/index-goe-lucene5/_3.cfe
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_3.cfs b/src/main/resources/index-goe-lucene5/_3.cfs
deleted file mode 100644
index f2ec38e..0000000
--- a/src/main/resources/index-goe-lucene5/_3.cfs
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_3.si b/src/main/resources/index-goe-lucene5/_3.si
deleted file mode 100644
index c1fbcdf..0000000
--- a/src/main/resources/index-goe-lucene5/_3.si
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_4.cfe b/src/main/resources/index-goe-lucene5/_4.cfe
deleted file mode 100644
index 34cda7d..0000000
--- a/src/main/resources/index-goe-lucene5/_4.cfe
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_4.cfs b/src/main/resources/index-goe-lucene5/_4.cfs
deleted file mode 100644
index 224beae..0000000
--- a/src/main/resources/index-goe-lucene5/_4.cfs
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/_4.si b/src/main/resources/index-goe-lucene5/_4.si
deleted file mode 100644
index 84a3366..0000000
--- a/src/main/resources/index-goe-lucene5/_4.si
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/segments_1 b/src/main/resources/index-goe-lucene5/segments_1
deleted file mode 100644
index 1cb809a..0000000
--- a/src/main/resources/index-goe-lucene5/segments_1
+++ /dev/null
Binary files differ
diff --git a/src/main/resources/index-goe-lucene5/write.lock b/src/main/resources/index-goe-lucene5/write.lock
deleted file mode 100644
index e69de29..0000000
--- a/src/main/resources/index-goe-lucene5/write.lock
+++ /dev/null
diff --git a/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
index 6952945..ce7be2b 100644
--- a/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourceFinderTest.java
@@ -38,11 +38,11 @@
     @Test
     public void testResourcesDemoFiltered () throws KustvaktException {
         Set<Corpus> resources = ResourceFinder.searchPublicFiltered(
-                Corpus.class, "WPD15");
+                Corpus.class, "WPD13");
         assertNotEquals(0, resources.size());
         assertEquals(1, resources.size());
 
-        resources = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD15",
+        resources = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD13",
                 "GOE");
         assertNotEquals(0, resources.size());
         assertEquals(2, resources.size());
diff --git a/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java b/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
index 72dd407..fb83bb4 100644
--- a/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/ResourcesTest.java
@@ -109,7 +109,7 @@
 
     @Test
     public void getDemoResourceFiltered () throws KustvaktException {
-        Set s = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD15");
+        Set s = ResourceFinder.searchPublicFiltered(Corpus.class, "WPD13");
         assertEquals(1, s.size());
     }
 
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java
index 8a94c44..522d3b3 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/LightServiceTest.java
@@ -145,11 +145,10 @@
 
 	@Test
 	public void testMatchInfoGet1 () {
-		// match-WPD_AAA.00001-p4-5
         ClientResponse response = resource()
 			.path(getAPIVersion())
-			//.path("corpus/GOE/AGI.00200/p13576-13577/matchInfo")
-			.path("corpus/WPD/AAA.00001/p4-5/matchInfo")
+			.path("corpus/GOE/AGI/04846/p36875-36876/matchInfo")
+			//.path("corpus/WPD/AAA.00001/p4-5/matchInfo")
 			.queryParam("foundry", "*")
 			.queryParam("spans", "false")
 			.get(ClientResponse.class);
@@ -158,16 +157,16 @@
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
-        assertEquals("WPD/AAA/00001", node.at("/textSigle").asText());
+        assertEquals("GOE/AGI/04846", node.at("/textSigle").asText());
+        assertEquals("Zweiter römischer Aufenthalt", node.at("/title").asText());
 	};
 
 	@Test
 	public void testMatchInfoGet2 () {
-		// match-WPD_AAA.00001-p4-5
         ClientResponse response = resource()
 			.path(getAPIVersion())
-			//.path("corpus/GOE/AGI.00200/p13576-13577/matchInfo")
-			.path("corpus/WPD/AAA.00001/p4-5/matchInfo")
+			.path("corpus/GOE/AGI/04846/p36875-36876/matchInfo")
+			//.path("corpus/WPD/AAA.00001/p4-5/matchInfo")
 			.queryParam("foundry", "*")
 			.get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -175,7 +174,8 @@
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
-        assertEquals("WPD/AAA/00001", node.at("/textSigle").asText());
+        assertEquals("GOE/AGI/04846", node.at("/textSigle").asText());
+        assertEquals("Zweiter römischer Aufenthalt", node.at("/title").asText());
 	};
 
     @Test
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
new file mode 100644
index 0000000..4e2f9d2
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -0,0 +1,103 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+
+public class MatchInfoServiceTest extends FastJerseyTest {
+
+    @BeforeClass
+    public static void configure () throws Exception {
+        FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+                "de.ids_mannheim.korap.web.filter",
+                "de.ids_mannheim.korap.web.utils");
+    }
+
+
+    @Test
+    public void testGetMatchInfoPublicCorpus () {
+
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("corpus").path("GOE").path("AGI").path("04846")
+                .path("p36875-36876").path("matchInfo")
+                .queryParam("foundry", "*")
+                .get(ClientResponse.class);
+
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertNotNull(node);
+        assertEquals("GOE/AGI/04846", node.at("/textSigle").asText());
+        assertEquals("Zweiter römischer Aufenthalt",
+                node.at("/title").asText());
+        assertEquals("vom Juni 1787 bis April 1788",
+                node.at("/subTitle").asText());
+        assertEquals("Goethe, Johann Wolfgang von",
+                node.at("/author").asText());
+        assertTrue(node.at("/snippet").asText()
+                .startsWith("<span class=\"context-left\"></span>"
+                        + "<span class=\"match\"><span title=\"corenlp/p:ADV\">"
+                        + "<span title=\"opennlp/p:ADV\">"
+                        + "<span title=\"tt/l:fern\">"
+                        ));
+    }
+
+    @Test
+    public void testGetMatchInfoWithAuthentication () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("corpus").path("WPD15").path("B07").path("51608")
+                .path("p46-57").path("matchInfo")
+                .queryParam("foundry", "*")
+                .header(Attributes.AUTHORIZATION,
+                        BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+                .get(ClientResponse.class);
+
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String entity = response.getEntity(String.class);
+        System.out.println(entity);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertNotNull(node);
+        assertEquals("WPD15/B07/51608", node.at("/textSigle").asText());
+        assertEquals("Betty Allen",
+                node.at("/title").asText());
+        assertEquals("Monsieurbecker, u.a.",
+                node.at("/author").asText());
+        assertTrue(!node.at("/snippet").asText().isEmpty());
+    }
+//    @Test
+//    public void testMatchInfoSave () {
+//
+//    }
+//
+//
+//    @Test
+//    public void testMatchInfoDelete () {
+//
+//    }
+//
+//
+//    @Test
+//    public void testGetMatches () {
+//
+//    }
+
+
+    @Override
+    public void initMethod () throws KustvaktException {
+        helper().runBootInterfaces();
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
index ebd094d..9b77a8b 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/QuerySerializationServiceTest.java
@@ -12,7 +12,6 @@
 import java.util.Iterator;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -43,7 +42,7 @@
     public void testQuerySerializationFilteredPublic () {
         ClientResponse response = resource()
                 .path(getAPIVersion())
-                .path("corpus/WPD15/search")
+                .path("corpus/WPD13/search")
                 .queryParam("q", "[orth=der]")
                 .queryParam("ql", "poliqarp")
                 .queryParam("context", "base/s:s")
@@ -54,7 +53,7 @@
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertEquals("corpusSigle", node.at("/collection/key").asText());
-        assertEquals("WPD15", node.at("/collection/value").asText());
+        assertEquals("WPD13", node.at("/collection/value").asText());
     }
     
     
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
similarity index 87%
rename from src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoTest.java
rename to src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
index f7aaaaf..2dba542 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceInfoServiceTest.java
@@ -21,7 +21,7 @@
  * @lastUpdate 19/04/2017
  *
  */
-public class ResourceInfoTest extends FastJerseyTest {
+public class ResourceInfoServiceTest extends FastJerseyTest {
 
     @Override
     public void initMethod () throws KustvaktException {
@@ -38,7 +38,7 @@
 
 
     @Test
-    public void testGetPublicVirtualCollections () {
+    public void testGetPublicVirtualCollectionInfo () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("collection").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -51,7 +51,7 @@
 
 
     @Test
-    public void testGetVirtualCollectionsWithAuthentication () {
+    public void testGetVirtualCollectionInfoWithAuthentication () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("collection")
                 .header(Attributes.AUTHORIZATION,
@@ -68,7 +68,7 @@
 
 
     @Test
-    public void testGetVirtualCollectionById () {
+    public void testGetVirtualCollectionInfoById () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("collection").path("WPD15-VC").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -85,7 +85,7 @@
 
 
     @Test
-    public void testGetPublicCorpora () {
+    public void testGetPublicCorporaInfo () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("corpus").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -99,22 +99,23 @@
 
 
     @Test
-    public void testGetCorpusById () {
+    public void testGetCorpusInfoById () {
         ClientResponse response = resource().path(getAPIVersion())
-                .path("corpus").path("WPD15").get(ClientResponse.class);
-        String ent = response.getEntity(String.class);
+                .path("corpus").path("WPD13").get(ClientResponse.class);
+        
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
                 response.getStatus());
-
+        String ent = response.getEntity(String.class);
+        System.out.println(ent);
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertTrue(node.isObject());
-        assertEquals("WPD15", node.path("id").asText());
+        assertEquals("WPD13", node.path("id").asText());
     }
 
 
     @Test
-    public void testGetCorpusById2 () {
+    public void testGetCorpusInfoById2 () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("corpus").path("GOE").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -128,7 +129,7 @@
 
 
     @Test
-    public void testGetPublicFoundries () {
+    public void testGetPublicFoundriesInfo () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("foundry").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -142,7 +143,7 @@
 
 
     @Test
-    public void testGetFoundryById () {
+    public void testGetFoundryInfoById () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("foundry").path("tt").get(ClientResponse.class);
         String ent = response.getEntity(String.class);
@@ -156,7 +157,7 @@
 
 
     @Test
-    public void testGetUnexistingCorpus () {
+    public void testGetUnexistingCorpusInfo () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("corpus").path("ZUW19").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
@@ -170,9 +171,9 @@
 
 
     // EM: queries for an unauthorized corpus get the same responses / treatment as 
-    // asking for an unexisting corpus. Does it need a specific exception instead?
+    // asking for an unexisting corpus info. Does it need a specific exception instead?
     @Test
-    public void testGetUnauthorizedCorpus () {
+    public void testGetUnauthorizedCorpusInfo () {
         ClientResponse response = resource().path(getAPIVersion())
                 .path("corpus").path("BRZ10").get(ClientResponse.class);
         assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
index cb642da..4b4840d 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceServiceTest.java
@@ -1,13 +1,11 @@
 package de.ids_mannheim.korap.web.service.full;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-import java.util.Iterator;
 
 import org.apache.http.HttpStatus;
 import org.junit.Assert;
@@ -17,13 +15,11 @@
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sun.jersey.api.client.ClientResponse;
 
 import de.ids_mannheim.korap.config.Attributes;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.handlers.ResourceDao;
-import de.ids_mannheim.korap.query.serialize.QuerySerializer;
 import de.ids_mannheim.korap.resources.KustvaktResource;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
 import de.ids_mannheim.korap.user.User;
@@ -35,7 +31,6 @@
  * @date 14/01/2016
  */
 public class ResourceServiceTest extends FastJerseyTest {
-    private static ObjectMapper mapper = new ObjectMapper();
     
     @BeforeClass
     public static void configure () throws Exception {
@@ -81,8 +76,6 @@
         assertTrue(docs < 15);
     }
 
-    
-
     // EM: The test covers multiple operations because it deals with 
     // the same resource and needs an order to operate (store followed by
     // update followed by delete).
@@ -104,7 +97,6 @@
                 response.getStatus());
         
         String ent = response.getEntity(String.class);
-        
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertTrue(node.isObject());
@@ -136,10 +128,11 @@
                 .post(ClientResponse.class);
         
         assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
-        JsonNode errorNode = mapper.readTree(response.getEntityInputStream());
+        
+        node = JsonUtils.readTree(response.getEntity(String.class));
         assertEquals(
                 "[No change has found.]",
-                errorNode.get("errors").get(0).get(2).asText());
+                node.get("errors").get(0).get(2).asText());
         
         // update resource service
         response = resource()
@@ -183,31 +176,6 @@
         assertEquals(null,res);
     }
 
-
-    
-    @Test
-    public void testMatchInfoGet () {
-    }
-
-
-    @Test
-    public void testMatchInfoSave () {
-
-    }
-
-
-    @Test
-    public void testMatchInfoDelete () {
-
-    }
-
-
-    @Test
-    public void testGetMatches () {
-
-    }
-
-
     @Override
     public void initMethod () throws KustvaktException {
         helper().runBootInterfaces();
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index e77647a..a6f6edd 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -5,6 +5,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -43,16 +44,17 @@
         ClientResponse response = resource().path(getAPIVersion())
                 .path("search").queryParam("q", "[orth=der]")
                 .queryParam("ql", "poliqarp").get(ClientResponse.class);
-        assertEquals(response.getStatus(),
-                ClientResponse.Status.OK.getStatusCode());
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertEquals("koral:docGroup", node.at("/collection/@type").asText());
         assertEquals("operation:or", node.at("/collection/operation").asText());
         assertNotEquals(0, node.at("/collection/operands").size());
-        assertEquals("corpusSigle([GOE, WPD15])",
+        assertEquals("corpusSigle([GOE, WPD13])",
                 node.at("/collection/rewrites/0/scope").asText());
+        assertEquals(6218, node.at("/meta/totalResults").asInt());
     }
 
 
@@ -66,12 +68,13 @@
                 .get(ClientResponse.class);
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
                 response.getStatus());
-
-        JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
         assertNotNull(node);
         assertNotEquals(0, node.path("matches").size());
-        assertEquals("corpusSigle([BRZ10, GOE, WPD15])",
+        assertEquals("corpusSigle([GOE, WPD13, WPD15, BRZ10])",
                 node.at("/collection/rewrites/0/scope").asText());
+        assertEquals(7665, node.at("/meta/totalResults").asInt());
     }
 
 
@@ -109,11 +112,31 @@
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertNotEquals(0, node.path("matches").size());
-        assertEquals("corpusSigle([GOE, WPD15])",
+        assertEquals("corpusSigle([GOE, WPD13])",
                 node.at("/collection/rewrites/0/scope").asText());
     }
 
 
+    @Test
+    @Ignore
+    public void testSearchPublicCorpusWithID () {
+        ClientResponse response = resource().path(getAPIVersion())
+                .path("corpus").path("GOE").path("search")
+                .queryParam("q", "blau").queryParam("ql", "poliqarp")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String ent = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(ent);
+        assertNotNull(node);
+        assertEquals("koral:docGroup", node.at("/collection/@type").asText());
+        assertEquals("operation:or", node.at("/collection/operation").asText());
+        assertNotEquals(0, node.at("/collection/operands").size());
+        assertEquals("corpusSigle([GOE])",
+                node.at("/collection/rewrites/0/scope").asText());
+        assertEquals(6218, node.at("/meta/totalResults").asInt());
+    }
+
 
     @Test
     public void testSearchSentenceMeta () {
@@ -146,7 +169,7 @@
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertNotEquals(0, node.path("matches").size());
-        assertEquals(17027, node.at("/meta/totalResults").asInt());
+        //        assertEquals(17027, node.at("/meta/totalResults").asInt());
     }
 
 
@@ -166,7 +189,7 @@
         JsonNode node = JsonUtils.readTree(ent);
         assertNotNull(node);
         assertNotEquals(0, node.path("matches").size());
-        assertEquals(10993, node.at("/meta/totalResults").asInt());
+        //        assertEquals(10993, node.at("/meta/totalResults").asInt());
     }
 
 }
diff --git a/src/test/resources/index-kustvakt-example/_0.cfe b/src/test/resources/index-kustvakt-example/_0.cfe
deleted file mode 100644
index 0ab94f8..0000000
--- a/src/test/resources/index-kustvakt-example/_0.cfe
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/index-kustvakt-example/_0.cfs b/src/test/resources/index-kustvakt-example/_0.cfs
deleted file mode 100644
index 0577152..0000000
--- a/src/test/resources/index-kustvakt-example/_0.cfs
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/index-kustvakt-example/_0.si b/src/test/resources/index-kustvakt-example/_0.si
deleted file mode 100644
index 50e865c..0000000
--- a/src/test/resources/index-kustvakt-example/_0.si
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/index-kustvakt-example/segments_1 b/src/test/resources/index-kustvakt-example/segments_1
deleted file mode 100644
index b6b0a45..0000000
--- a/src/test/resources/index-kustvakt-example/segments_1
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/policy-test.conf b/src/test/resources/policy-test.conf
index 4156a76..a4c49bd 100644
--- a/src/test/resources/policy-test.conf
+++ b/src/test/resources/policy-test.conf
@@ -2,7 +2,8 @@
 
 virtualcollection	WPD15-VC	Wikipedia Virtual Collection	German Wikipedia 2015	public	read	corpusSigle=WPD15 & creationDate since 2014-04-01	
 virtualcollection	BRZ10-PC	Braunschweiger Collection	Selected Braunschweiger Zeitung	ids	read	corpusSigle=BRZ10 & foundries ~ Connexor
-corpus	WPD15	Wikipedia	German Wikipedia 2015	public	read
+corpus	WPD13	Wikipedia 2013	Public German Wikipedia 2013	public	read
+corpus	WPD15	Wikipedia 2015	IDS German Wikipedia 2015	ids	read
 corpus	GOE	Goethe	Goethe corpus	public	read
 corpus	BRZ10	Braunschweiger	Braunschweiger Zeitung 2010	ids	read
 type	id	name	description	condition	permissions
diff --git a/src/test/resources/sample-index/_0.cfe b/src/test/resources/sample-index/_0.cfe
new file mode 100644
index 0000000..8abc486
--- /dev/null
+++ b/src/test/resources/sample-index/_0.cfe
Binary files differ
diff --git a/src/test/resources/sample-index/_0.cfs b/src/test/resources/sample-index/_0.cfs
new file mode 100644
index 0000000..63efeb7
--- /dev/null
+++ b/src/test/resources/sample-index/_0.cfs
Binary files differ
diff --git a/src/test/resources/sample-index/_0.si b/src/test/resources/sample-index/_0.si
new file mode 100644
index 0000000..fe1bebe
--- /dev/null
+++ b/src/test/resources/sample-index/_0.si
Binary files differ
diff --git a/src/test/resources/sample-index/_1.cfe b/src/test/resources/sample-index/_1.cfe
new file mode 100644
index 0000000..a515fac
--- /dev/null
+++ b/src/test/resources/sample-index/_1.cfe
Binary files differ
diff --git a/src/test/resources/sample-index/_1.cfs b/src/test/resources/sample-index/_1.cfs
new file mode 100644
index 0000000..be27ceb
--- /dev/null
+++ b/src/test/resources/sample-index/_1.cfs
Binary files differ
diff --git a/src/test/resources/sample-index/_1.si b/src/test/resources/sample-index/_1.si
new file mode 100644
index 0000000..5764d53
--- /dev/null
+++ b/src/test/resources/sample-index/_1.si
Binary files differ
diff --git a/src/test/resources/sample-index/segments_1 b/src/test/resources/sample-index/segments_1
new file mode 100644
index 0000000..b1944d5
--- /dev/null
+++ b/src/test/resources/sample-index/segments_1
Binary files differ
diff --git a/src/test/resources/index-kustvakt-example/write.lock b/src/test/resources/sample-index/write.lock
similarity index 100%
rename from src/test/resources/index-kustvakt-example/write.lock
rename to src/test/resources/sample-index/write.lock