Added limit of hits to be exported
Change-Id: Ib2cb1972d0cd56568b54f0dbdfe2dd925e25f0f5
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
new file mode 100644
index 0000000..e5eb5be
--- /dev/null
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
@@ -0,0 +1,19 @@
+/**
+ *
+ * @author helge
+ *
+ * Class to define the constants of the export web service,
+ * like the maximum hits to be exported
+ *
+ */
+package de.ids_mannheim.korap.plkexport;
+
+public class ExWSConf {
+ /*
+ * maximum hits to be exported
+ * TODO: Define this constants after discussing it.
+ * Maybe we need an distinction between user at the IDS and external user
+ * See also: https://www.ids-mannheim.de/cosmas2/script-app/hilfe/sitzung.html
+ */
+ public static final int MAX_EXP_LIMIT = 10000;
+}
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
index d09e73f..3a89ae3 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
@@ -29,6 +29,7 @@
import static com.tutego.jrtf.RtfPara.*;
import static com.tutego.jrtf.RtfText.*;
+
@Path("/")
public class IdsExportService {
@@ -48,12 +49,14 @@
*
*
*/
+
@POST
@Path("export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response testjsonform (@FormParam("fname") String fname,
@FormParam("format") String format, @FormParam("q") String q,
- @FormParam("ql") String ql) throws IOException {
+ @FormParam("ql") String ql, @FormParam("islimit") String il,
+ @FormParam("hitc") int hitc) throws IOException {
String[][] params = { { "fname", fname }, { "format", format },
{ "q", q }, { "ql", ql } };
@@ -69,8 +72,17 @@
ResponseBuilder builder;
Client client = ClientBuilder.newClient();
+
String url = "http://localhost:8089/api/v1.0/search?context=sentence"
+ "&q=" + URLEncoder.encode(q, "UTF-8") + "&ql=" + ql;
+
+ if (il != null) {
+ url = url + "&cutoff=1" + "&count=" + hitc;
+ }
+
+ else {
+ url = url + "&cutoff=1" + "&count=" + ExWSConf.MAX_EXP_LIMIT;
+ }
WebTarget resource = client.target(url);
String resp = resource.request(MediaType.APPLICATION_JSON)
.get(String.class);
@@ -96,6 +108,8 @@
LinkedList<MatchExport> listMatches = new LinkedList();
ObjectMapper objectMapper = new ObjectMapper();
MatchExport match;
+
+
for (Iterator<JsonNode> itNode = jsonNode1.elements(); itNode
.hasNext();) {
match = objectMapper.readValue(itNode.next().toString(),
@@ -103,7 +117,6 @@
listMatches.addLast(match);
}
-
String rtfresp = writeRTF(listMatches);
builder = Response.ok(rtfresp);
builder.header("Content-Disposition",
diff --git a/plugin/templates/export.html b/plugin/templates/export.html
index 294d910..404a7cf 100644
--- a/plugin/templates/export.html
+++ b/plugin/templates/export.html
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<!-- TODO: style, localization, remove Zu Testzwecken in the end, ...-->
+<!-- TODO: style, localization, remove 'Zu Testzwecken' in the end, ...-->
<html>
<head>
<meta charset="UTF-8">
@@ -9,7 +9,7 @@
<body>
<form id ="frmid" action="http://localhost:7777/export" method="POST">
- Zu Testzwecken: <br />
+ Zu Testzwecken: <br/>
<ul>
<li> <a onclick="KorAPlugin.requestMsg({'action':'get', 'key':'KQ'}, function (d) { document.write(JSON.stringify(d.value))})">Get KQ</a> </li>
</ul>
@@ -18,16 +18,28 @@
<label for="ql"> Suchanfragesprache:</label>
<input id="ql" name="ql" value="poliqarp">
<input type="hidden" id="cq" name="cq" value="">
- <br />
- <br />
- <br />
+ <br/>
+ <br/>
+ <br/>
<label for="fname">Dateiname:</label>
- <input type="text" id="fname" name="fname" required> <br>
+ <input type="text" id="fname" name="fname" required> <br/>
Dateiformat:
<input type="radio" id="formatjson" name="format" value="json">
<label for="formatjson">JSON</label>
<input type="radio" checked="checked" id="formathtml" name="format" value="rtf">
- <label for="formatrtf">RTF</label><br>
+ <label for="formatrtf">RTF</label><br/>
+
+ <div>
+ <br/>
+ <label>
+ <input type="checkbox" name="islimit" checked="checked" value="limited">
+ Beschränken auf
+ <input name="hitc" type="number" min="1" max="1000" value="20">
+ Treffer
+ </label>
+ <br/>
+ <br/>
+ </div>
<button> Exportieren </button>
</form>
</body>