| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.search; |
| 2 | |
| 3 | import java.util.*; |
| 4 | import java.io.*; |
| 5 | |
| 6 | import static de.ids_mannheim.korap.TestSimple.*; |
| 7 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 8 | import de.ids_mannheim.korap.Krill; |
| Nils Diewald | 2d5f810 | 2015-02-26 21:07:54 +0000 | [diff] [blame] | 9 | import de.ids_mannheim.korap.KrillCollection; |
| Nils Diewald | 0339d46 | 2015-02-26 14:53:56 +0000 | [diff] [blame] | 10 | import de.ids_mannheim.korap.KrillQuery; |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 11 | import de.ids_mannheim.korap.KrillIndex; |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 12 | import de.ids_mannheim.korap.index.FieldDocument; |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 13 | import de.ids_mannheim.korap.response.Result; |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 14 | import java.nio.file.Files; |
| 15 | import java.nio.file.FileSystem; |
| 16 | import java.nio.file.Path; |
| 17 | import java.nio.charset.StandardCharsets; |
| 18 | import java.nio.ByteBuffer; |
| 19 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 20 | import org.apache.commons.lang.StringUtils; |
| 21 | import org.apache.lucene.analysis.Analyzer; |
| 22 | import org.apache.lucene.analysis.TokenStream; |
| 23 | import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| 24 | |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 25 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 26 | import com.fasterxml.jackson.databind.JsonNode; |
| 27 | |
| 28 | import static org.junit.Assert.*; |
| 29 | import org.junit.Test; |
| 30 | import org.junit.Ignore; |
| 31 | import org.junit.runner.RunWith; |
| 32 | import org.junit.runners.JUnit4; |
| 33 | |
| 34 | @RunWith(JUnit4.class) |
| 35 | public class TestMetaFields { |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 36 | |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 37 | @Test |
| 38 | public void searchMetaFields () throws IOException { |
| 39 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 40 | // Construct index |
| Nils Diewald | a14ecd6 | 2015-02-26 21:00:20 +0000 | [diff] [blame] | 41 | KrillIndex ki = new KrillIndex(); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 42 | // Indexing test files |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | for (String i : new String[] { "00001", "00002" }) { |
| Nils Diewald | 5033355 | 2015-03-02 15:54:46 +0000 | [diff] [blame] | 44 | ki.addDoc( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 45 | getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), |
| 46 | true); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 47 | }; |
| 48 | ki.commit(); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 49 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 50 | String jsonString = getString(getClass().getResource( |
| 51 | "/queries/metas/fields.jsonld").getFile()); |
| 52 | |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 53 | Krill ks = new Krill(jsonString); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 54 | |
| Nils Diewald | 884dbcf | 2015-02-27 17:02:28 +0000 | [diff] [blame] | 55 | Result kr = ks.apply(ki); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 56 | assertEquals((long) 17, kr.getTotalResults()); |
| 57 | assertEquals(0, kr.getStartIndex()); |
| 58 | assertEquals(9, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 59 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 60 | ObjectMapper mapper = new ObjectMapper(); |
| 61 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| Akron | b116644 | 2015-06-27 00:34:19 +0200 | [diff] [blame] | 62 | |
| 63 | // System.err.println(res.toString()); |
| 64 | // mirror fields |
| 65 | assertEquals(9, res.at("/meta/count").asInt()); |
| 66 | |
| 67 | if (res.at("/meta/fields/0").asText().equals("UID")) { |
| 68 | assertEquals("corpusID", res.at("/meta/fields/1").asText()); |
| 69 | } |
| 70 | else { |
| 71 | assertEquals("corpusID", res.at("/meta/fields/0").asText()); |
| 72 | assertEquals("UID", res.at("/meta/fields/1").asText()); |
| 73 | }; |
| 74 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 75 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| 76 | assertEquals("WPD", res.at("/matches/0/corpusID").asText()); |
| Akron | 12f1f5b | 2015-06-24 15:56:52 +0200 | [diff] [blame] | 77 | assertTrue(res.at("/matches/0/docID").isMissingNode()); |
| 78 | assertTrue(res.at("/matches/0/textSigle").isMissingNode()); |
| 79 | assertTrue(res.at("/matches/0/ID").isMissingNode()); |
| 80 | assertTrue(res.at("/matches/0/author").isMissingNode()); |
| 81 | assertTrue(res.at("/matches/0/title").isMissingNode()); |
| 82 | assertTrue(res.at("/matches/0/subTitle").isMissingNode()); |
| 83 | assertTrue(res.at("/matches/0/textClass").isMissingNode()); |
| 84 | assertTrue(res.at("/matches/0/pubPlace").isMissingNode()); |
| 85 | assertTrue(res.at("/matches/0/pubDate").isMissingNode()); |
| 86 | assertTrue(res.at("/matches/0/foundries").isMissingNode()); |
| 87 | assertTrue(res.at("/matches/0/layerInfos").isMissingNode()); |
| 88 | assertTrue(res.at("/matches/0/tokenization").isMissingNode()); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 89 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 90 | jsonString = getString(getClass().getResource( |
| 91 | "/queries/metas/fields_2.jsonld").getFile()); |
| Nils Diewald | bbd39a5 | 2015-02-23 19:56:57 +0000 | [diff] [blame] | 92 | ks = new Krill(jsonString); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 93 | kr = ks.apply(ki); |
| 94 | assertEquals((long) 17, kr.getTotalResults()); |
| 95 | assertEquals(0, kr.getStartIndex()); |
| 96 | assertEquals(2, kr.getItemsPerPage()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 97 | |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 98 | mapper = new ObjectMapper(); |
| 99 | res = mapper.readTree(kr.toJsonString()); |
| 100 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| Akron | 12f1f5b | 2015-06-24 15:56:52 +0200 | [diff] [blame] | 101 | assertTrue(res.at("/matches/0/corpusID").isMissingNode()); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 102 | assertEquals("Ruru,Jens.Ol,Aglarech", res.at("/matches/0/author") |
| 103 | .asText()); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 104 | assertEquals("A", res.at("/matches/0/title").asText()); |
| 105 | assertEquals("WPD_AAA.00001", res.at("/matches/0/docID").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 106 | assertTrue(res.at("/matches/0/textSigle").isMissingNode()); |
| Akron | 7d45e6b | 2015-06-26 17:23:42 +0200 | [diff] [blame] | 107 | assertEquals("match-WPD_AAA.00001-p6-7", res.at("/matches/0/matchID") |
| 108 | .asText()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 109 | // assertEquals("p6-7", res.at("/matches/0/matchID").asText()); |
| Nils Diewald | 3aa9e69 | 2015-02-20 22:20:11 +0000 | [diff] [blame] | 110 | assertEquals("", res.at("/matches/0/subTitle").asText()); |
| 111 | assertEquals("", res.at("/matches/0/textClass").asText()); |
| 112 | assertEquals("", res.at("/matches/0/pubPlace").asText()); |
| 113 | assertEquals("", res.at("/matches/0/pubDate").asText()); |
| 114 | assertEquals("", res.at("/matches/0/foundries").asText()); |
| 115 | assertEquals("", res.at("/matches/0/layerInfo").asText()); |
| 116 | assertEquals("", res.at("/matches/0/tokenization").asText()); |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 117 | }; |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 118 | |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 119 | |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 120 | @Test |
| 121 | public void searchMetaFieldsNew () throws IOException { |
| 122 | |
| 123 | // Construct index |
| 124 | KrillIndex ki = new KrillIndex(); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 125 | ki.addDoc(getClass().getResourceAsStream("/goe/AGX-00002.json"), false); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 126 | ki.commit(); |
| 127 | |
| 128 | String jsonString = getString(getClass().getResource( |
| 129 | "/queries/metas/fields_no.jsonld").getFile()); |
| 130 | |
| 131 | Krill ks = new Krill(jsonString); |
| 132 | Result kr = ks.apply(ki); |
| 133 | ObjectMapper mapper = new ObjectMapper(); |
| 134 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 135 | assertEquals(0, res.at("/matches/0/UID").asInt()); |
| 136 | assertEquals("GOE_AGX.00002", res.at("/matches/0/textSigle").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 137 | assertEquals("Maximen und Reflexionen", res.at("/matches/0/title") |
| 138 | .asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 139 | assertEquals("1982", res.at("/matches/0/pubDate").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 140 | assertEquals("Goethe, Johann Wolfgang von", res.at("/matches/0/author") |
| 141 | .asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 142 | assertEquals("GOE_AGX", res.at("/matches/0/docSigle").asText()); |
| 143 | assertEquals("GOE", res.at("/matches/0/corpusSigle").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 144 | assertEquals("Religion und Christentum", res.at("/matches/0/subTitle") |
| 145 | .asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 146 | assertEquals("München", res.at("/matches/0/pubPlace").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 147 | assertEquals( |
| 148 | "base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans", |
| 149 | res.at("/matches/0/layerInfos").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 150 | assertTrue(res.at("/matches/0/textType").isMissingNode()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 151 | assertEquals("match-GOE_AGX.00002-p7-8", res.at("/matches/0/matchID") |
| 152 | .asText()); |
| 153 | |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 154 | |
| 155 | // All fields |
| 156 | jsonString = getString(getClass().getResource( |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 157 | "/queries/metas/fields_all.jsonld").getFile()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 158 | |
| 159 | ks = new Krill(jsonString); |
| 160 | kr = ks.apply(ki); |
| 161 | mapper = new ObjectMapper(); |
| 162 | res = mapper.readTree(kr.toJsonString()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 163 | assertEquals("Verlag C. H. Beck", res.at("/matches/0/publisher") |
| 164 | .asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 165 | assertEquals("Aphorismus", res.at("/matches/0/textType").asText()); |
| 166 | assertEquals("Aphorismen", res.at("/matches/0/textTypeRef").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 167 | assertEquals( |
| 168 | "Goethe, Johann Wolfgang von: Maximen und Reflexionen. Religion und Christentum, [Aphorismen], (Erstveröffentlichung: Stuttgart ; Tübingen, 1827-1842), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 12, Schriften zur Kunst. Schriften zur Literatur. Maximen und Reflexionen, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 372-377", |
| 169 | res.at("/matches/0/reference").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 170 | assertEquals("de", res.at("/matches/0/language").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 171 | assertEquals("opennlp#tokens", res.at("/matches/0/tokenSource") |
| 172 | .asText()); |
| 173 | assertEquals( |
| 174 | "base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/constituency corenlp/morpho corenlp/namedentities corenlp/sentences glemm glemm/morpho mate mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences", |
| 175 | res.at("/matches/0/foundries").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 176 | assertEquals("Goethe-Korpus", res.at("/matches/0/corpusTitle").asText()); |
| 177 | assertEquals("QAO-NC", res.at("/matches/0/license").asText()); |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 178 | assertEquals("Goethe: Maximen und Reflexionen, (1827-1842)", |
| 179 | res.at("/matches/0/docTitle").asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 180 | assertEquals("1827", res.at("/matches/0/creationDate").asText()); |
| 181 | assertEquals("372-377", res.at("/matches/0/pages").asText()); |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 182 | assertEquals("match-GOE_AGX.00002-p7-8", res.at("/matches/0/matchID") |
| Akron | 640458c | 2015-06-25 12:36:15 +0200 | [diff] [blame] | 183 | .asText()); |
| Akron | 6590c32 | 2015-07-02 16:08:13 +0200 | [diff] [blame] | 184 | |
| 185 | |
| 186 | // @All fields |
| 187 | jsonString = getString(getClass().getResource( |
| 188 | "/queries/metas/fields_at_all.jsonld").getFile()); |
| 189 | |
| 190 | ks = new Krill(jsonString); |
| 191 | kr = ks.apply(ki); |
| 192 | mapper = new ObjectMapper(); |
| 193 | res = mapper.readTree(kr.toJsonString()); |
| 194 | |
| 195 | assertEquals("Verlag C. H. Beck", res.at("/matches/0/publisher") |
| 196 | .asText()); |
| 197 | assertEquals("Aphorismus", res.at("/matches/0/textType").asText()); |
| 198 | assertEquals("Aphorismen", res.at("/matches/0/textTypeRef").asText()); |
| 199 | assertEquals( |
| 200 | "Goethe, Johann Wolfgang von: Maximen und Reflexionen. Religion und Christentum, [Aphorismen], (Erstveröffentlichung: Stuttgart ; Tübingen, 1827-1842), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 12, Schriften zur Kunst. Schriften zur Literatur. Maximen und Reflexionen, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 372-377", |
| 201 | res.at("/matches/0/reference").asText()); |
| 202 | assertEquals("de", res.at("/matches/0/language").asText()); |
| 203 | assertEquals("opennlp#tokens", res.at("/matches/0/tokenSource") |
| 204 | .asText()); |
| 205 | assertEquals( |
| 206 | "base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/constituency corenlp/morpho corenlp/namedentities corenlp/sentences glemm glemm/morpho mate mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/morpho xip/sentences", |
| 207 | res.at("/matches/0/foundries").asText()); |
| 208 | assertEquals("Goethe-Korpus", res.at("/matches/0/corpusTitle").asText()); |
| 209 | assertEquals("QAO-NC", res.at("/matches/0/license").asText()); |
| 210 | assertEquals("Goethe: Maximen und Reflexionen, (1827-1842)", |
| 211 | res.at("/matches/0/docTitle").asText()); |
| 212 | assertEquals("1827", res.at("/matches/0/creationDate").asText()); |
| 213 | assertEquals("372-377", res.at("/matches/0/pages").asText()); |
| 214 | assertEquals("match-GOE_AGX.00002-p7-8", res.at("/matches/0/matchID") |
| 215 | .asText()); |
| Akron | 3e0403f | 2015-06-24 20:59:13 +0200 | [diff] [blame] | 216 | }; |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 217 | |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 218 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 219 | @Test |
| 220 | public void searchCollectionFields () throws IOException { |
| 221 | KrillIndex ki = new KrillIndex(); |
| 222 | FieldDocument fd = new FieldDocument(); |
| 223 | fd.addString("corpusSigle", "ABC"); |
| 224 | fd.addString("docSigle", "ABC-123"); |
| 225 | fd.addString("textSigle", "ABC-123-0001"); |
| 226 | fd.addText("title", "Die Wahlverwandschaften"); |
| 227 | fd.addText("author", "Johann Wolfgang von Goethe"); |
| 228 | fd.addKeyword("textClass", "reisen wissenschaft"); |
| 229 | fd.addInt("pubDate", 20130617); |
| 230 | fd.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 231 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]"); |
| 232 | ki.addDoc(fd); |
| 233 | |
| 234 | FieldDocument fd2 = new FieldDocument(); |
| 235 | fd2.addString("corpusSigle", "ABC"); |
| 236 | fd2.addString("docSigle", "ABC-125"); |
| 237 | fd2.addString("textSigle", "ABC-125-0001"); |
| 238 | fd2.addText("title", "Die Glocke"); |
| 239 | fd2.addText("author", "Schiller, Friedrich"); |
| 240 | fd2.addKeyword("textClass", "Reisen geschichte"); |
| 241 | fd2.addInt("pubDate", 20130203); |
| 242 | fd2.addTV("tokens", "abc", "[(0-1)s:a|i:a|_0#0-1|-:t$<i>10]" |
| 243 | + "[(1-2)s:b|i:b|_1#1-2]" + "[(2-3)s:c|i:c|_2#2-3]"); |
| 244 | ki.addDoc(fd2); |
| 245 | ki.commit(); |
| 246 | |
| 247 | // textClass = reisen & wissenschaft |
| 248 | String jsonString = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 249 | "/queries/collections/collection_textClass.jsonld").getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 250 | Krill ks = new Krill(jsonString); |
| 251 | KrillCollection kc = ks.getCollection(); |
| 252 | kc.setIndex(ki); |
| 253 | assertEquals(1, kc.getCount()); // 1 filter operation |
| 254 | assertEquals(1, kc.numberOf("documents")); |
| 255 | |
| 256 | // textClass = reisen |
| 257 | jsonString = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 258 | "/queries/collections/collection_textClass_2.jsonld").getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 259 | ks = new Krill(jsonString); |
| 260 | kc = ks.getCollection(); |
| 261 | kc.setIndex(ki); |
| 262 | assertEquals(1, kc.getCount()); // 1 filter operation |
| 263 | assertEquals(2, kc.numberOf("documents")); |
| 264 | |
| 265 | /* |
| 266 | System.err.println(StringUtils.join(fd2.doc.getValues("textClass"), ",")); |
| 267 | System.err.println(StringUtils.join(fd2.doc.getValues("author"), ", ")); |
| 268 | */ |
| 269 | /* |
| 270 | TokenStream ts = fd2.doc.getField("author").tokenStream( |
| 271 | (Analyzer) ki.writer().getAnalyzer(), |
| 272 | (TokenStream) null |
| 273 | ); |
| 274 | // OffsetAttribute offsetAttribute = ts.addAttribute(OffsetAttribute.class); |
| 275 | CharTermAttribute charTermAttribute = ts.addAttribute(CharTermAttribute.class); |
| 276 | |
| 277 | ts.reset(); |
| 278 | while (ts.incrementToken()) { |
| 279 | String term = charTermAttribute.toString(); |
| 280 | System.err.println(">>" + term + "<<"); |
| 281 | }; |
| 282 | */ |
| 283 | |
| 284 | // author = wolfgang |
| 285 | jsonString = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 286 | "/queries/collections/collection_goethe.jsonld").getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 287 | ks = new Krill(jsonString); |
| 288 | kc = ks.getCollection(); |
| 289 | kc.setIndex(ki); |
| 290 | assertEquals(1, kc.getCount()); // 1 filter operation |
| 291 | assertEquals(1, kc.numberOf("documents")); |
| 292 | |
| 293 | // author = Wolfgang |
| 294 | jsonString = getString(getClass().getResource( |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 295 | "/queries/collections/collection_goethe_2.jsonld").getFile()); |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 296 | ks = new Krill(jsonString); |
| 297 | kc = ks.getCollection(); |
| 298 | kc.setIndex(ki); |
| 299 | assertEquals(1, kc.getCount()); // 1 filter operation |
| 300 | assertEquals(1, kc.numberOf("documents")); |
| 301 | |
| 302 | Result kr = ks.apply(ki); |
| Akron | 4055017 | 2015-08-04 03:06:12 +0200 | [diff] [blame] | 303 | |
| Akron | 484c3c1 | 2015-07-07 20:25:44 +0200 | [diff] [blame] | 304 | ObjectMapper mapper = new ObjectMapper(); |
| 305 | JsonNode res = mapper.readTree(kr.toJsonString()); |
| 306 | assertEquals(1, res.at("/meta/totalResults").asInt()); |
| 307 | }; |
| 308 | |
| Akron | 48937e9 | 2015-06-26 01:49:02 +0200 | [diff] [blame] | 309 | |
| 310 | @Test |
| 311 | public void searchMetaContext () throws IOException { |
| 312 | |
| 313 | // All fields |
| 314 | String jsonString = getString(getClass().getResource( |
| 315 | "/queries/metas/context_paragraph.jsonld").getFile()); |
| 316 | |
| 317 | Krill ks = new Krill(jsonString); |
| 318 | assertTrue(ks.getMeta().getContext().isSpanDefined()); |
| 319 | assertEquals("base/p", ks.getMeta().getContext().getSpanContext()); |
| 320 | }; |
| Nils Diewald | e364570 | 2014-11-07 21:15:20 +0000 | [diff] [blame] | 321 | }; |