Add fields array to matches in search
Change-Id: Icf037eadb8e43e2d02d9447caabedf9c4974871e
diff --git a/Changes b/Changes
index b1935da..8c3e963 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,7 @@
-0.63.0 2024-06-21
+0.63.1 2024-06-24
+ - [feature] Add fields array to matches in search responses (diewald)
+
+0.63.0 2024-06-24
- [bugfix] Show all inline markers and pagebreaks at match borders (diewald).
- [feature] Show inline markers and pagebreaks in contexts (diewald).
- [bugfix] Prevent matches in contexts (diewald).
diff --git a/pom.xml b/pom.xml
index 579c1d4..d227e54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
<groupId>de.ids-mannheim.korap.krill</groupId>
<artifactId>Krill</artifactId>
- <version>0.63.0</version>
+ <version>0.63.1</version>
<packaging>jar</packaging>
<name>Krill</name>
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 5340e2f..1eceb5a 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -6,13 +6,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
@@ -2488,6 +2482,15 @@
if (this.hasTokens)
json.set("tokens", this.getSnippetTokens());
+ 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());
+ };
+
return json;
};
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 516d486..353d428 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -234,6 +234,72 @@
assertTrue(res.at("/matches/0/namespace.new").isMissingNode());
};
+ @Test
+ public void searchMetaFieldsWithPeriods () throws IOException {
+
+ // Construct index
+ KrillIndex ki = new KrillIndex();
+ FieldDocument fd = ki.addDoc(getClass().getResourceAsStream("/others/KED-KLX-03212.json.gz"), true);
+
+ ki.commit();
+
+ String jsonString = getJsonString(getClass()
+ .getResource("/queries/metas/fields_with_periods.jsonld").getFile());
+
+ Krill ks = new Krill(jsonString);
+ Result kr = ks.apply(ki);
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res = mapper.readTree(kr.toJsonString());
+
+ String sv = fd.doc.getField("textSigle").stringValue();
+ assertEquals("KED/KLX/03212", sv);
+
+ sv = fd.doc.getField("KED.corpusRcpntLabel").stringValue();
+ assertEquals("data:,Kinder", sv);
+
+ assertEquals(1, res.at("/meta/totalResults").asInt());
+
+ 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());
+ assertFalse(res.at("/matches/0/fields").isMissingNode());
+
+ Iterator fieldIter = res.at("/matches/0/fields").elements();
+
+ int checkC = 0;
+ int checkF = 0;
+ while (fieldIter.hasNext()) {
+ JsonNode field = (JsonNode) fieldIter.next();
+
+ String key = field.at("/key").asText();
+
+ switch (key) {
+ case "KED.corpusRcpntLabel":
+ assertEquals("type:attachement", field.at("/type").asText());
+ assertEquals("koral:field", field.at("/@type").asText());
+ assertEquals("data:,Kinder", field.at("/value").asText());
+ checkC++;
+ break;
+ case "UID":
+ checkF++;
+ break;
+ case "textSigle":
+ assertEquals("type:string", field.at("/type").asText());
+ assertEquals("koral:field", field.at("/@type").asText());
+ assertEquals("KED/KLX/03212", field.at("/value").asText());
+ checkC++;
+ break;
+ default:
+ checkF++;
+ }
+ };
+
+ assertEquals(2, checkC);
+ assertEquals(0, checkF);
+ };
+
@Test
public void searchMetaFieldsDuplicateKeys () throws IOException {
diff --git a/src/test/resources/others/KED-KLX-03212.json.gz b/src/test/resources/others/KED-KLX-03212.json.gz
new file mode 100644
index 0000000..593dada
--- /dev/null
+++ b/src/test/resources/others/KED-KLX-03212.json.gz
Binary files differ
diff --git a/src/test/resources/queries/metas/fields_with_periods.jsonld b/src/test/resources/queries/metas/fields_with_periods.jsonld
new file mode 100644
index 0000000..4a02824
--- /dev/null
+++ b/src/test/resources/queries/metas/fields_with_periods.jsonld
@@ -0,0 +1,22 @@
+{
+ "@context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld",
+ "announcements" : [],
+ "errors" : [],
+ "meta" : {
+ "count":9,
+ "fields": [
+ "UID",
+ "KED.corpusRcpntLabel",
+ "textSigle"
+ ]
+ },
+ "query" : {
+ "@type" : "koral:token",
+ "wrap" : {
+ "@type" : "koral:term",
+ "key" : "beispielsweise",
+ "layer":"orth"
+ }
+ },
+ "warnings" : []
+}