Fix hit counting
Change-Id: I4adafaec7bbf0e4b97481f77984a95c7b51a6d9e
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
index 26a96c0..e19bd98 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/MatchAggregator.java
@@ -255,12 +255,12 @@
// Iterate over the results of the current file
Iterator<JsonNode> mNode = mNodes.elements();
while (mNode.hasNext()) {
- this.addMatch(mNode.next(), writer);
- this.fetchedResults++;
if (this.maxResults > 0 &&
- this.fetchedResults > this.maxResults) {
+ this.fetchedResults >= this.maxResults) {
return false;
};
+ this.addMatch(mNode.next(), writer);
+ this.fetchedResults++;
};
return true;
};
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
index d0fe1dd..14d7bb6 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
@@ -510,7 +510,7 @@
str = responsertf.readEntity(String.class);
assertTrue("Page 1 content", str.contains("Ironhoof"));
assertTrue("Page 2 content", str.contains("Sinologie"));
- assertTrue("Unicode handling", str.contains("Hintergr\\u252\\'fcnde"));
+ assertTrue("Unicode handling", str.contains("\\u252\\'fcbersetzt"));
assertTrue("TotalResults", str.contains("Count: \\f1 9\\"));
assertTrue("Fetched", str.contains("Fetched: \\f1 7\\"));
}
@@ -611,7 +611,7 @@
Response responsejson = target("/export").request()
.post(Entity.form(frmap));
- assertEquals("Request RTF: Http Response should be 200: ",
+ assertEquals("Request JSON: Http Response should be 200: ",
Status.OK.getStatusCode(), responsejson.getStatus());
String str = responsejson.readEntity(String.class);
@@ -625,7 +625,27 @@
assertEquals(obj.at("/matches/8/matchID").asText(),"match-WUD17/K35/39955-p16258-16259");
assertTrue(obj.at("/matches/0/snippet").asText().contains("<span class=\"context-right\">""));
assertTrue(obj.at("/matches/0/snippet").asText().contains("wie wär's"));
- }
+
+
+ frmap.putSingle("hitc", "7");
+
+ responsejson = target("/export").request()
+ .post(Entity.form(frmap));
+ assertEquals("Request JSON: Http Response should be 200: ",
+ Status.OK.getStatusCode(), responsejson.getStatus());
+
+ str = responsejson.readEntity(String.class);
+ parser = mapper.getFactory().createParser(str);
+ obj = mapper.readTree(parser);
+
+ assertEquals(obj.at("/query/@type").asText(),"koral:token");
+ assertEquals(obj.at("/meta/totalResults").asInt(),9);
+ assertEquals(obj.at("/matches/0/matchID").asText(),"match-WUD17/G59/34284-p4238-4239");
+ assertEquals(obj.at("/matches/1/matchID").asText(),"match-WUD17/C53/60524-p736-737");
+ assertEquals(obj.at("/matches/6/matchID").asText(),"match-WUD17/K35/39955-p16114-16115");
+ assertFalse(obj.has("/matches/7"));
+ };
+
@Test
public void testExportWsJsonWithMaxHitcFirstPage () throws IOException {