Introduce attachement mechanism
Change-Id: I8e3bca30ef051b5021ffc15b6157e25e37dd9da9
diff --git a/Changes b/Changes
index e54e88c..910ce3d 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.58.3 2018-12-12
+ - [feature] Introduced attachements as meta data fields (diewald).
+
0.58.2 2018-12-05
- [bugfix] Fixed the candidate list in NextSpans, see de.ids_mannheim.
korap.index.TestNextIndex.testNextExpansionBug() (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java b/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
index 95c65a2..a244282 100644
--- a/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
+++ b/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
@@ -109,6 +109,9 @@
doc.add(new StringField(key, value, Field.Store.YES));
};
+ public void addAttachement (String key, String value) {
+ doc.add(new StoredField(key, value));
+ };
public void addStored (String key, String value) {
doc.add(new StoredField(key, value));
diff --git a/src/main/java/de/ids_mannheim/korap/response/MetaFields.java b/src/main/java/de/ids_mannheim/korap/response/MetaFields.java
index e28a404..86607fd 100644
--- a/src/main/java/de/ids_mannheim/korap/response/MetaFields.java
+++ b/src/main/java/de/ids_mannheim/korap/response/MetaFields.java
@@ -110,8 +110,14 @@
// Stored
if (iFieldType.indexOptions() == IndexOptions.NONE) {
- mf.type = "type:store";
- mf.values.add(s.toString());
+ String value = s.toString();
+ if (value.startsWith("data:")) {
+ mf.type = "type:attachement";
+ }
+ else {
+ mf.type = "type:store";
+ };
+ mf.values.add(value);
}
// Keywords
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
index 77f7e87..513185e 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
@@ -23,8 +23,6 @@
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.util.QueryException;
-// mvn -Dtest=TestWithinIndex#indexExample1 test
-
@RunWith(JUnit4.class)
public class TestFieldDocument {
@@ -44,6 +42,7 @@
fd.addInt("lastModified", 20130717);
fd.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]"
+ "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]");
+ fd.addAttachement("Wikilink", "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
assertEquals(fd.doc.getField("title").name(), "title");
assertEquals(fd.doc.getField("title").stringValue(), "Wikipedia");
@@ -78,6 +77,10 @@
assertEquals(fd.doc.getField("textClass").name(), "textClass");
assertEquals(fd.doc.getField("textClass").stringValue(),
"music entertainment");
+ assertEquals(fd.doc.getField("Wikilink").name(), "Wikilink");
+ assertEquals(fd.doc.getField("Wikilink").stringValue(),
+ "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel"
+ );
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestKrillIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestKrillIndex.java
index 23f928e..f643944 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestKrillIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestKrillIndex.java
@@ -196,6 +196,7 @@
fd.addString("textSigle", "a/b/c");
fd.addInt("zahl1", 56);
fd.addStored("ref", "My reference");
+ fd.addAttachement("ref2", "data:text/plain;charset=UTF-8,My reference2");
fd.addKeyword("keyword", "baum");
fd.addKeyword("keyword", "wald");
@@ -227,6 +228,13 @@
checkC++;
break;
+ case "ref2":
+ assertEquals("type:attachement", field.at("/type").asText());
+ assertEquals("koral:field", field.at("/@type").asText());
+ assertEquals("data:text/plain;charset=UTF-8,My reference2", field.at("/value").asText());
+ checkC++;
+ break;
+
case "title":
assertEquals("type:text", field.at("/type").asText());
assertEquals("koral:field", field.at("/@type").asText());
@@ -265,7 +273,7 @@
};
};
- assertEquals(6, checkC);
+ assertEquals(7, checkC);
// Test with real document
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 022a6f6..4bf61c7 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestMetaFields.java
@@ -317,4 +317,29 @@
assertTrue(ks.getMeta().getContext().isSpanDefined());
assertEquals("base/p", ks.getMeta().getContext().getSpanContext());
};
+
+
+ @Test
+ public void searchMetaAssets () throws IOException {
+ KrillIndex ki = new KrillIndex();
+ FieldDocument fd = new FieldDocument();
+ fd.addString("textSigle", "ABC-123-0002");
+ fd.addText("title", "Die Wahlverwandtschaften");
+ fd.addText("author", "Johann Wolfgang von Goethe");
+ fd.addKeyword("textClass", "reisen wissenschaft");
+ fd.addInt("pubDate", 20130617);
+ fd.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]"
+ + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]");
+ fd.addAttachement("WikiLink", "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
+ ki.addDoc(fd);
+ ki.commit();
+
+ assertEquals(fd.doc.getField("textSigle").stringValue(), "ABC-123-0002");
+ assertEquals(fd.doc.getField("title").stringValue(), "Die Wahlverwandtschaften");
+ assertEquals(fd.doc.getField("author").stringValue(), "Johann Wolfgang von Goethe");
+ assertEquals(fd.doc.getField("textClass").stringValue(), "reisen wissenschaft");
+ assertEquals(fd.doc.getField("pubDate").stringValue(), "20130617");
+ assertEquals(fd.doc.getField("WikiLink").stringValue(), "data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
+ }
+
};