Support highlights in matchinfo
Change-Id: I37f70b12f98325f2a26374fb1c1a852df082cbc8
diff --git a/lite/Changes b/lite/Changes
index 97bd277..3d27a08 100644
--- a/lite/Changes
+++ b/lite/Changes
@@ -1,8 +1,9 @@
version 0.60
-15/03/2018
+23/03/2018
- updated field type:date in the metadata test (margaretha)
- removed loading application context via BeanFactory (margaretha)
- - fixed missing kustvakt-lite.conf (margaretha))
+ - fixed missing kustvakt-lite.conf (margaretha)
+ - added support for highlights in matchinfo (diewald)
version 0.59.9
01/02/2018
diff --git a/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java b/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
index cc37c2b..7eb5c2c 100644
--- a/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
+++ b/lite/src/main/java/de/ids_mannheim/korap/web/service/lite/LiteService.java
@@ -334,6 +334,8 @@
@QueryParam("foundry") Set<String> foundries,
@QueryParam("layer") Set<String> layers,
@QueryParam("spans") Boolean spans,
+ // Highlights may also be a list of valid highlight classes
+ @QueryParam("hls") Boolean highlights,
@Context HttpServletRequest request) throws KustvaktException {
String matchid =
@@ -349,6 +351,7 @@
f_list = new ArrayList<>(foundries);
spans = spans != null ? spans : false;
+ highlights = highlights != null ? highlights : false;
boolean match_only = foundries == null || foundries.isEmpty();
String results;
@@ -356,7 +359,7 @@
results = searchKrill.getMatch(matchid, null);
else
results = searchKrill.getMatch(matchid, f_list, l_list, spans,
- false, true, null);
+ highlights, true, null);
return Response.ok(results).build();
}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
index 79b1786..618bb04 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteServiceTest.java
@@ -195,8 +195,7 @@
@Test
public void testMatchInfoGetWithoutSpans () throws KustvaktException{
ClientResponse response = resource()
-
- .path("corpus/GOE/AGA/01784/p36-46/matchInfo")
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
.queryParam("foundry", "*")
.queryParam("spans", "false")
.get(ClientResponse.class);
@@ -206,10 +205,55 @@
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("Belagerung von Mainz", node.at("/title").asText());
};
@Test
+ public void testMatchInfoGetWithoutHighlights () throws KustvaktException{
+ ClientResponse response = resource()
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy")
+ .queryParam("spans", "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("<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>",
+ node.at("/snippet").asText());
+ 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("Belagerung von Mainz", node.at("/title").asText());
+ };
+
+
+ @Test
+ public void testMatchInfoGetWithHighlights () throws KustvaktException{
+ ClientResponse response = resource()
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy")
+ .queryParam("spans", "false")
+ .queryParam("hls", "true")
+ .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("<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; <mark class=\"class-5 level-0\">der <mark class=\"class-2 level-1\">Ort ist sehr zerschossen; dann</mark> über die Schiffbrücke</mark></mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>",
+ node.at("/snippet").asText());
+ assertEquals("match-GOE/AGA/01784-p36-46(5)37-45(2)38-42",
+ node.at("/matchID").asText());
+ assertEquals("Belagerung von Mainz", node.at("/title").asText());
+ };
+
+
+ @Test
public void testMatchInfoGet2 () throws KustvaktException{
ClientResponse response = resource()