Temporarily add all fields for matches as legacy flat fields
Change-Id: Ifb75bcd6e2707e49c8af2142f30242a566bf7b13
diff --git a/Changes b/Changes
index 8c3e963..467c752 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
0.63.1 2024-06-24
- [feature] Add fields array to matches in search responses (diewald)
+ - [feature] Temporarily add all requested fields in flat legacy fields
+ maps (diewald)
0.63.0 2024-06-24
- [bugfix] Show all inline markers and pagebreaks at match borders (diewald).
diff --git a/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java b/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
index 207a9cb..2979822 100644
--- a/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
+++ b/src/main/java/de/ids_mannheim/korap/index/AbstractDocument.java
@@ -361,7 +361,9 @@
return this.getFieldValue("ID");
};
- @JsonAnyGetter
+ //@JsonAnyGetter
+ @Deprecated
+ @JsonIgnore
public Map<String, JsonNode> getLegacyMetaFields () {
Iterator<MetaField> mfIterator = mFields.iterator();
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 1eceb5a..c5ab6ab 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -26,6 +26,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.node.TextNode;
import de.ids_mannheim.korap.index.AbstractDocument;
import de.ids_mannheim.korap.index.PositionsToOffset;
@@ -2489,7 +2490,15 @@
while (fIter.hasNext()) {
MetaField mf = fIter.next();
fields.add(mf.toJsonNode());
+
+ // Legacy flat field support
+ String mfs = mf.key;
+ String value = this.getFieldValue(mfs);
+ if (value != null)
+ json.set(mfs, new TextNode(value));
};
+
+ this.addMessage(0, "Support for flat field values is eprecated");
return json;
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/Text.java b/src/main/java/de/ids_mannheim/korap/response/Text.java
index 2cf3e6d..68dab3c 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Text.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Text.java
@@ -8,6 +8,9 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -39,8 +42,26 @@
public String toJsonString () {
- JsonNode json = (JsonNode) this.toJsonNode();
+ ObjectNode json = (ObjectNode) this.toJsonNode();
+ ArrayNode fields = json.putArray("fields");
+
+ // Iterate over all fields
+ Iterator<MetaField> fIter = mFields.iterator();
+ while (fIter.hasNext()) {
+ MetaField mf = fIter.next();
+ fields.add(mf.toJsonNode());
+
+ // Legacy flat field support
+ String mfs = mf.key;
+ String value = this.getFieldValue(mfs);
+ if (value != null)
+ json.set(mfs, new TextNode(value));
+ };
+
+ this.addMessage(0, "Support for flat field values is eprecated");
+
+
// Match was no match
if (json.size() == 0)
return "{}";
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
index 353d428..bbf1b3e 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -262,8 +262,7 @@
assertEquals(0, res.at("/matches/0/UID").asInt());
assertEquals("KED/KLX/03212", res.at("/matches/0/textSigle").asText());
assertTrue(res.at("/matches/0/title").isMissingNode());
- // assertEquals("data:,Kinder", res.at("/matches/0/KED.corpusRcpntLabel").asText());
- assertTrue(res.at("/matches/0/KED.corpusRcpntLabel").isMissingNode());
+ assertEquals("data:,Kinder", res.at("/matches/0/KED.corpusRcpntLabel").asText());
assertFalse(res.at("/matches/0/fields").isMissingNode());
Iterator fieldIter = res.at("/matches/0/fields").elements();