Added show-tokens option to the search API.
Change-Id: I16c71bccdd5b21e1475edde22b656be24c11287f
diff --git a/full/Changes b/full/Changes
index 02f043e..d84e29a 100644
--- a/full/Changes
+++ b/full/Changes
@@ -18,7 +18,8 @@
- [security] More log4j security updates
- Bumped unboundid-ldapsdk
- Updated tests.
-
+2022-01-25
+ - Added show-tokens option to the search API.
# version 0.64.1
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
similarity index 99%
rename from full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java
rename to full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
index d772eb2..3050ff6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/PublicMetadataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
@@ -17,7 +17,7 @@
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.utils.JsonUtils;
-public class PublicMetadataTest extends SpringJerseyTest {
+public class SearchPublicMetadataTest extends SpringJerseyTest {
@Test
public void testSearchPublicMetadata () throws KustvaktException {
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
new file mode 100644
index 0000000..c04f8a2
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
@@ -0,0 +1,78 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+public class SearchTokenSnippetTest extends SpringJerseyTest {
+
+ @Test
+ public void testSearchWithTokens () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(ent);
+
+ assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
+ assertTrue(node.at("/matches/0/hasTokens").asBoolean());
+ assertTrue(node.at("/matches/0/tokens/left").size()>0);
+ assertTrue(node.at("/matches/0/tokens/right").size()>0);
+ assertEquals(1, node.at("/matches/0/tokens/match").size());
+ }
+
+ @Test
+ public void testSearchWithoutTokens () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "false")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(ent);
+
+ assertTrue(node.at("/matches/0/hasSnippet").asBoolean());
+ assertFalse(node.at("/matches/0/hasTokens").asBoolean());
+ assertTrue(node.at("/matches/0/tokens").isMissingNode());
+ }
+
+ @Test
+ public void testSearchPublicMetadataWithTokens () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(ent);
+
+ assertFalse(node.at("/matches/0/hasSnippet").asBoolean());
+ assertFalse(node.at("/matches/0/hasTokens").asBoolean());
+ assertTrue(node.at("/matches/0/snippet").isMissingNode());
+ assertTrue(node.at("/matches/0/tokens").isMissingNode());
+
+ assertEquals(StatusCodes.NOT_ALLOWED, node.at("/warnings/0/0").asInt());
+ }
+}