Introduced preliminary support for meta data field retrieval
Change-Id: Id0eb88341d1d1a36725f65a4d40d6b36622edb06
diff --git a/core/pom.xml b/core/pom.xml
index d110402..2e8728d 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -261,7 +261,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Krill</artifactId>
- <version>0.56.1</version>
+ <version>0.56.2</version>
<exclusions>
<exclusion>
<groupId>org.xerial</groupId>
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 c7123b8..9051484 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
@@ -18,6 +18,7 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.response.Match;
+import de.ids_mannheim.korap.response.MetaFields;
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.util.QueryException;
@@ -144,6 +145,29 @@
};
+ /*
+ * Retrieve the meta fields for a certain document
+ */
+ public String getFields (String id) {
+ MetaFields meta;
+
+ // No index found
+ if (this.index == null) {
+ meta = new MetaFields(id);
+ meta.addError(601, "Unable to find index");
+ }
+
+ // Index available
+ else {
+
+ //Get fields
+ meta = this.index.getFields(id);
+ };
+ return meta.toJsonString();
+ };
+
+
+
public String getMatch (String id, List<String> foundries,
List<String> layers, boolean includeSpans,
boolean includeHighlights, boolean sentenceExpansion,
@@ -285,4 +309,16 @@
.append('/').append(textID).append('-').append(matchID);
return sb.toString();
};
+
+
+ /**
+ * Return the text sigle as a string.
+ */
+ public String getTextSigle (String corpusID, String docID, String textID) {
+ // Create a string representation of the match
+ StringBuilder sb = new StringBuilder();
+ sb.append(corpusID).append('/').append(docID)
+ .append('/').append(textID);
+ return sb.toString();
+ };
};
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 73ce86e..cc37c2b 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
@@ -361,4 +361,23 @@
return Response.ok(results).build();
}
+
+ /*
+ * Returns the meta data fields of a certain document
+ */
+ @GET
+ @Path("/corpus/{corpusId}/{docId}/{textId}")
+ public Response getMeta (
+ @PathParam("corpusId") String corpusId,
+ @PathParam("docId") String docId,
+ @PathParam("textId") String textId,
+ // @QueryParam("fields") Set<String> fields,
+ @Context HttpServletRequest request) throws KustvaktException {
+
+ String textSigle = searchKrill.getTextSigle(corpusId, docId, textId);
+
+ String results = searchKrill.getFields(textSigle);
+
+ 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 b0d6284..1d1c41b 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
@@ -5,6 +5,7 @@
import static org.junit.Assert.assertNotNull;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.*;
import org.apache.lucene.LucenePackage;
import org.junit.Test;
@@ -261,4 +262,58 @@
assertEquals("WPD", node.at("/collection/operands/1/value").asText());
}
+ @Test
+ public void testMetaFields () throws KustvaktException {
+ ClientResponse response = resource()
+ .path("/corpus/GOE/AGA/01784")
+ .method("GET", ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String resp = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(resp);
+ System.err.println(node.toString());
+
+ Iterator fieldIter = node.at("/document/fields").elements();
+
+ int checkC = 0;
+ while (fieldIter.hasNext()) {
+ JsonNode field = (JsonNode) fieldIter.next();
+
+ String key = field.at("/key").asText();
+
+ assertEquals("koral:field", field.at("/@type").asText());
+
+ switch (key) {
+ case "textSigle":
+ assertEquals("type:string", field.at("/type").asText());
+ assertEquals("GOE/AGA/01784", field.at("/value").asText());
+ checkC++;
+ break;
+ case "author":
+ assertEquals("type:text", field.at("/type").asText());
+ assertEquals("Goethe, Johann Wolfgang von", field.at("/value").asText());
+ checkC++;
+ break;
+ case "docSigle":
+ assertEquals("type:string", field.at("/type").asText());
+ assertEquals("GOE/AGA", field.at("/value").asText());
+ checkC++;
+ break;
+ case "docTitle":
+ assertEquals("type:text", field.at("/type").asText());
+ assertEquals(
+ "Goethe: Autobiographische Schriften II, (1817-1825, 1832)",
+ field.at("/value").asText()
+ );
+ checkC++;
+ break;
+ case "pubDate":
+ assertEquals("type:number", field.at("/type").asText());
+ assertEquals(19820000, field.at("/value").asInt());
+ checkC++;
+ break;
+ };
+ };
+ assertEquals(5, checkC);
+ };
}