Merge "Introduced query reference rewrite mechanism"
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/pom.xml b/core/pom.xml
index 408b419..769d492 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -8,10 +8,10 @@
 	<properties>
 		<java.version>1.8</java.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<spring.version>5.2.9.RELEASE</spring.version>
+		<spring.version>5.3.0</spring.version>
 		<jersey.version>1.19.4</jersey.version>
-		<jetty.version>9.4.31.v20200723</jetty.version>
-		<hibernate.version>5.3.7.Final</hibernate.version>
+		<jetty.version>9.4.34.v20201102</jetty.version>
+		<hibernate.version>5.4.20.Final</hibernate.version>
 		<log4j.version>2.13.3</log4j.version>
 	</properties>
 	<build>
@@ -231,12 +231,12 @@
 		<dependency>
 			<groupId>org.projectlombok</groupId>
 			<artifactId>lombok</artifactId>
-			<version>1.18.12</version>
+			<version>1.18.16</version>
 		</dependency>
 		<dependency>
 			<groupId>joda-time</groupId>
 			<artifactId>joda-time</artifactId>
-			<version>2.10.6</version>
+			<version>2.10.8</version>
 		</dependency>
 		<dependency>
 			<groupId>de.ids_mannheim.korap</groupId>
@@ -460,7 +460,7 @@
 		<dependency>
 			<groupId>org.apache.httpcomponents</groupId>
 			<artifactId>httpclient</artifactId>
-			<version>4.5.12</version>
+			<version>4.5.13</version>
 		</dependency>
 		<dependency>
 			<groupId>commons-io</groupId>
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/full/pom.xml b/full/pom.xml
index b225554..575cd9b 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -8,7 +8,7 @@
 		<java.version>1.8</java.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<jersey.version>1.19.4</jersey.version>
-		<hibernate.version>5.3.7.Final</hibernate.version>
+		<hibernate.version>5.4.23.Final</hibernate.version>
 	</properties>
 	<profiles>
 		<profile>
@@ -307,14 +307,14 @@
 		<dependency>
 			<groupId>com.nimbusds</groupId>
 			<artifactId>nimbus-jose-jwt</artifactId>
-			<version>9.1.1</version>
+			<version>9.1.2</version>
 		</dependency>
 
 		<!-- OpenId -->
 		<dependency>
 			<groupId>com.nimbusds</groupId>
 			<artifactId>oauth2-oidc-sdk</artifactId>
-			<version>8.23.1</version>
+			<version>8.25</version>
 		</dependency>
 
 		<!-- Project Lombok -->
diff --git a/lite/pom.xml b/lite/pom.xml
index d80b3e4..b40e638 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -129,6 +129,18 @@
 					</execution>
 				</executions>
 			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>cobertura-maven-plugin</artifactId>
+				<version>2.7</version>
+				<configuration>
+					<formats>
+						<format>html</format>
+						<format>xml</format>
+					</formats>
+					<check/>
+				</configuration>
+			</plugin>
 		</plugins>
 	</build>
 
@@ -160,5 +172,18 @@
 			<version>1.18.16</version>
 			<scope>provided</scope>
 		</dependency>
+		<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/cobertura-maven-plugin -->
+		<dependency>
+			<groupId>org.codehaus.mojo</groupId>
+			<artifactId>cobertura-maven-plugin</artifactId>
+			<version>2.7</version>
+			<scope>test</scope>
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/backport-util-concurrent/backport-util-concurrent -->
+		<dependency>
+			<groupId>backport-util-concurrent</groupId>
+			<artifactId>backport-util-concurrent</artifactId>
+			<version>3.1</version>
+		</dependency>
 	</dependencies>
 </project>
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")