Support expand query parameter for match retrieval

Change-Id: I9cf360441207ad86dcd76de1020368e409fe3d0d
diff --git a/.gitignore b/.gitignore
index 4e95513..95d91a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,7 +8,7 @@
 *.iml
 dependency-reduced-pom.xml
 admin_token
-/sandbox/
+/sandbox
 /bin/
 /db.sqlite
 /lite/liteDB.sqlite
diff --git a/core/Changes b/core/Changes
index 8700115..611af1f 100644
--- a/core/Changes
+++ b/core/Changes
@@ -5,6 +5,8 @@
    - Removed salt from config and updated config files.
 05/02/2020
    - Added welcome page.
+01/04/2020
+   - Support expand query parameter for match retrieval (diewald)
 11/05/2020
    - Added tool to create VC from list (diewald)
 29/05/2020
diff --git a/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java b/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
index 2d414f9..18a349c 100644
--- a/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
+++ b/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
@@ -360,13 +360,14 @@
     public String retrieveMatchInfo (String corpusId, String docId,
             String textId, String matchId, Set<String> foundries,
             String username, HttpHeaders headers, Set<String> layers,
-            boolean spans, boolean highlights) throws KustvaktException {
+            boolean spans, boolean sentenceExpansion,
+            boolean highlights) throws KustvaktException {
         String matchid =
                 searchKrill.getMatchId(corpusId, docId, textId, matchId);
 
         User user = createUser(username, headers);
         Pattern p = determineAvailabilityPattern(user);
-        
+
         boolean match_only = foundries == null || foundries.isEmpty();
         String results;
 //        try {
@@ -387,7 +388,7 @@
                 }
 
                 results = searchKrill.getMatch(matchid, foundryList, layerList,
-                        spans, highlights, true, p);
+                        spans, highlights, sentenceExpansion, p);
             }
             else {
                 results = searchKrill.getMatch(matchid, p);
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 8096c77..27665a2 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -33,10 +33,6 @@
 
     private static final boolean DEBUG = false;
 
-    // Temporary - shouldn't be here.
-    String indexDir = "/data/prep_corpus/index/";
-    String i = "/Users/hanl/Projects/prep_corpus";
-    String klinux10 = "/vol/work/hanl/indices";
     public static KrillIndex index;
 
     /**
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java b/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
index 128a0de..e3967b4 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
@@ -238,7 +238,7 @@
             @QueryParam("hls") Boolean highlights) throws KustvaktException {
 
         return retrieveMatchInfo(ctx, headers, locale, corpusId, docId, textId,
-                matchId, foundries, layers, spans, highlights);
+                                 matchId, foundries, layers, spans, "sentence", highlights);
     }
     
     @GET
@@ -253,9 +253,15 @@
             @QueryParam("foundry") Set<String> foundries,
             @QueryParam("layer") Set<String> layers,
             @QueryParam("spans") Boolean spans, 
+            @QueryParam("expand") String expansion, 
             // Highlights may also be a list of valid highlight classes
             @QueryParam("hls") Boolean highlights) throws KustvaktException {
 
+        Boolean expandToSentence = true;
+        if (expansion != null && (expansion.equals("false") || expansion.equals("null"))) {
+            expandToSentence = false;
+        }
+
         TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
         scopeService.verifyScope(tokenContext, OAuth2Scope.MATCH_INFO);
         spans = spans != null ? spans : false;
@@ -265,7 +271,7 @@
         try{
             String results = searchService.retrieveMatchInfo(corpusId, docId,
                     textId, matchId, foundries, tokenContext.getUsername(),
-                    headers, layers, spans, highlights);
+                    headers, layers, spans, expandToSentence, highlights);
             return Response.ok(results).build();
         }
         catch (KustvaktException e) {
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
index 4c2dd28..479ea57 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
@@ -223,6 +223,27 @@
     };
 
     @Test
+    public void testMatchInfoWithoutExtension () throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION)
+                .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42")
+                .queryParam("foundry", "-").queryParam("spans", "false")
+                .queryParam("expand","false")
+                .get(ClientResponse.class);
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+                response.getStatus());
+        String ent = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(ent);
+        assertNotNull(node);
+        assertEquals("GOE/AGA/01784", node.at("/textSigle").asText());
+        assertEquals("match-GOE/AGA/01784-p36-46(5)37-45(2)38-42",
+                node.at("/matchID").asText());
+        assertEquals("<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark></span><span class=\"context-right\"><span class=\"more\"></span></span>",
+                node.at("/snippet").asText());
+        assertEquals("Belagerung von Mainz", node.at("/title").asText());
+    };
+
+    
+    @Test
     public void testMatchInfoGetWithHighlights () throws KustvaktException {
         ClientResponse response = resource().path(API_VERSION)
                 .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")