Always mirror a given matchID
Change-Id: I7876332e6a4180220a066268fdee3a943c08bed9
diff --git a/Changes b/Changes
index 3b0b09c..1ed8d2e 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.56.2 2018-03-20
+0.56.2 2018-03-23
- [feature] Introduce meta field retrieval method (diewald)
- [cleanup] Rename KrillQuery's "_"-method to "nr" to improve
compatibility with future versions of Java (diewald)
@@ -13,7 +13,9 @@
- [feature] Serialize dates in dash separation format, when
metadata field name ends with "Date" (diewald)
- [bugfix] Fixed left exclusion-expansion when there is no
- more span for SpanOrQuery (margaretha)
+ more span for SpanOrQuery (margaretha)
+ - [bugfix] Fixed matchID response to be always identical to
+ a given matchID (diewald)
0.56.1 2018-01-31
- [bugfix] Changed relation serialization in snippet to work
diff --git a/src/main/java/de/ids_mannheim/korap/response/Match.java b/src/main/java/de/ids_mannheim/korap/response/Match.java
index 81d4c2e..d67fdba 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -128,7 +128,11 @@
private int startPage = -1;
private int endPage = -1;
- private String tempSnippet, snippetHTML, snippetBrackets, identifier;
+ private String tempSnippet,
+ snippetHTML,
+ snippetBrackets,
+ identifier,
+ mirrorIdentifier;
private HighlightCombinator snippetArray;
@@ -186,7 +190,9 @@
*/
public Match (String idString, boolean includeHighlights) {
MatchIdentifier id = new MatchIdentifier(idString);
+
if (id.getStartPos() > -1) {
+ this.mirrorIdentifier = id.toString();
if (id.getTextSigle() != null)
this.setTextSigle(id.getTextSigle());
@@ -204,7 +210,7 @@
if (pos[0] < id.getStartPos() || pos[1] > id.getEndPos())
continue;
this.addHighlight(pos[0], pos[1], pos[2]);
- };
+ };
};
};
@@ -666,10 +672,16 @@
@Override
@JsonProperty("matchID")
public String getID () {
+
+ // Return identifier as given
+ if (this.mirrorIdentifier != null) {
+ return this.mirrorIdentifier;
+ };
- // Identifier already given
- if (this.identifier != null)
+ // Identifier already created
+ if (this.identifier != null) {
return this.identifier;
+ };
// No, nada, nix
if (this.localDocID == -1)
@@ -1098,7 +1110,7 @@
this.processed = false;
this.snippetHTML = null;
this.snippetBrackets = null;
- this.identifier = null;
+ this.identifier = null;
// Delete all spans
if (this.span != null)
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index 6f35916..f87f4b1 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -174,13 +174,17 @@
"... [[{f/m:acht:b}{f/m:neun:a}]] ...",
km.getSnippetBrackets());
-
+ // Mirror identifier when passed
km = ki.getMatchInfo("match-c1!d1-p7-9(0)8-8(2)7-8", "tokens", "f",
null, false, false);
assertEquals("SnippetBrackets (1b)",
"... [[{f/m:acht:{f/y:eight:b}}{f/m:neun:{f/y:nine:a}}]] ...",
km.getSnippetBrackets());
+ JsonNode res = mapper.readTree(km.toJsonString());
+ assertEquals("match-c1!d1-p7-9(0)8-8(2)7-8",
+ res.at("/matchID").asText());
+
km = ki.getMatchInfo("match-c1!d1-p7-9(0)8-8(2)7-8", "tokens", "f", "m",
false, true);
@@ -216,7 +220,7 @@
+ "<span class=\"more\">" + "</span>" + "</span>",
km.getSnippetHTML());
- JsonNode res = mapper.readTree(km.toJsonString());
+ res = mapper.readTree(km.toJsonString());
assertEquals("tokens", res.at("/field").asText());
assertTrue(res.at("/startMore").asBoolean());
assertTrue(res.at("/endMore").asBoolean());