Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 1 | import com.fasterxml.jackson.databind.JsonNode; |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 2 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 3 | import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder; |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 4 | import de.ids_mannheim.korap.utils.JsonUtils; |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 5 | import org.junit.Ignore; |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 6 | import org.junit.Test; |
| 7 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 8 | import static org.junit.Assert.assertEquals; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 9 | import static org.junit.Assert.assertNotEquals; |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 10 | import static org.junit.Assert.assertNotNull; |
| 11 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 12 | /** |
| 13 | * @author hanl |
| 14 | * @date 12/08/2015 |
| 15 | */ |
| 16 | public class CollectionQueryBuilderTest { |
| 17 | |
| 18 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 19 | public void testsimpleAdd () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 20 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 21 | b.with("corpusSigle=WPD"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 22 | |
| 23 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 24 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 25 | assertNotNull(node); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 26 | assertEquals("koral:doc", node.at("/collection/@type").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 27 | assertEquals("corpusSigle", node.at("/collection/key").asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 30 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 31 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 32 | public void testSimpleConjunction () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 33 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 34 | b.with("corpusSigle=WPD & textClass=freizeit"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 35 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 36 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 37 | assertNotNull(node); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 38 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 39 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 40 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 41 | assertEquals("corpusSigle", node.at("/collection/operands/0/key").asText()); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 42 | assertEquals("textClass", node.at("/collection/operands/1/key") |
| 43 | .asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 44 | } |
| 45 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 46 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 47 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 48 | public void testSimpleDisjunction () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 49 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 50 | b.with("corpusSigle=WPD | textClass=freizeit"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 51 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 52 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 53 | assertNotNull(node); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 54 | assert node.at("/collection/operation").asText().equals("operation:or"); |
| 55 | assert node.at("/collection/operands/0/key").asText() |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 56 | .equals("corpusSigle"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 57 | assert node.at("/collection/operands/1/key").asText() |
| 58 | .equals("textClass"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 61 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 62 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 63 | public void testComplexSubQuery () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 64 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 65 | b.with("(corpusSigle=WPD) | (textClass=freizeit & corpusSigle=BRZ13)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 66 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 67 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 68 | assertNotNull(node); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 69 | assert node.at("/collection/operation").asText().equals("operation:or"); |
| 70 | assert node.at("/collection/operands/0/key").asText() |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 71 | .equals("corpusSigle"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 72 | assert node.at("/collection/operands/1/@type").asText() |
| 73 | .equals("koral:docGroup"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 74 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 77 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 78 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 79 | public void testAddResourceQueryAfter () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 80 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 81 | b.with("(textClass=politik & title=\"random title\") | textClass=wissenschaft"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 82 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 83 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 84 | c.setBaseQuery(b.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 85 | c.with("corpusSigle=WPD"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 86 | |
| 87 | JsonNode node = JsonUtils.readTree(c.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 88 | assertNotNull(node); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 89 | assertEquals("koral:doc", node.at("/collection/operands/1/@type") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 90 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 91 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 92 | .asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 93 | assertEquals(2, node.at("/collection/operands").size()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 94 | assertEquals(2, node.at("/collection/operands/0/operands").size()); |
| 95 | assertEquals(2, node.at("/collection/operands/0/operands/0/operands").size()); |
| 96 | |
| 97 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 98 | assertEquals("operation:or", node.at("/collection/operands/0/operation").asText()); |
| 99 | assertEquals("operation:and", node.at("/collection/operands/0/operands/0/operation").asText()); |
| 100 | assertEquals("WPD", node.at("/collection/operands/1/value").asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 103 | |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 104 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 105 | public void testAddComplexResourceQueryAfter () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 106 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 107 | b.with("(title=\"random title\") | (textClass=wissenschaft)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 108 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 109 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 110 | c.setBaseQuery(b.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 111 | c.with("(corpusSigle=BRZ13 | corpusSigle=AZPS)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 112 | |
| 113 | JsonNode node = JsonUtils.readTree(c.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 114 | assertNotNull(node); |
| 115 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 116 | .asText()); |
| 117 | assertEquals("koral:docGroup", node.at("/collection/operands/1/@type") |
| 118 | .asText()); |
| 119 | assertEquals("BRZ13", node |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 120 | .at("/collection/operands/1/operands/0/value").asText()); |
| 121 | assertEquals("AZPS", node.at("/collection/operands/1/operands/1/value") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 122 | .asText()); |
| 123 | assertEquals("random title", |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 124 | node.at("/collection/operands/0/operands/0/value").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 125 | assertEquals("wissenschaft", |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 126 | node.at("/collection/operands/0/operands/1/value").asText()); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 129 | |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 130 | @Test |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 131 | public void testBuildQuery () { |
| 132 | String coll = "corpusSigle=WPD"; |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 133 | String query = "[base=Haus]"; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 134 | QuerySerializer check = new QuerySerializer(); |
| 135 | check.setQuery(query, "poliqarp"); |
| 136 | check.setCollection(coll); |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 137 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 138 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 139 | b.setBaseQuery(check.toJSON()); |
| 140 | b.with("textClass=freizeit"); |
| 141 | |
| 142 | JsonNode res = (JsonNode) b.rebaseCollection(); |
| 143 | assertNotNull(res); |
| 144 | assertEquals("koral:docGroup", res.at("/collection/@type").asText()); |
| 145 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 146 | assertEquals("koral:doc", res.at("/collection/operands/0/@type") |
| 147 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 148 | assertEquals("freizeit", res.at("/collection/operands/1/value") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 149 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 150 | assertEquals("textClass", res.at("/collection/operands/1/key").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 151 | |
| 152 | assertEquals("koral:doc", res.at("/collection/operands/1/@type") |
| 153 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 154 | assertEquals("WPD", res.at("/collection/operands/0/value").asText()); |
| 155 | assertEquals("corpusSigle", res.at("/collection/operands/0/key").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 156 | |
| 157 | // check also that query is still there |
| 158 | assertEquals("koral:token", res.at("/query/@type").asText()); |
| 159 | assertEquals("koral:term", res.at("/query/wrap/@type").asText()); |
| 160 | assertEquals("Haus", res.at("/query/wrap/key").asText()); |
| 161 | assertEquals("lemma", res.at("/query/wrap/layer").asText()); |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 164 | |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 165 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 166 | public void testBaseQueryBuild () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 167 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 168 | b.with("(corpusSigle=ADF) | (textClass=freizeit & corpusSigle=WPD)"); |
| 169 | |
| 170 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
| 171 | c.setBaseQuery(b.toJSON()); |
| 172 | |
| 173 | c.with("corpusSigle=BRZ13"); |
| 174 | JsonNode base = (JsonNode) c.rebaseCollection(); |
| 175 | assertNotNull(base); |
| 176 | assertEquals(base.at("/collection/@type").asText(), "koral:docGroup"); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 177 | assertEquals(base.at("/collection/operands/1/@type").asText(), |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 178 | "koral:doc"); |
| 179 | assertEquals(base.at("/collection/operands/1/value").asText(), "BRZ13"); |
| 180 | assertEquals(base.at("/collection/operands/0/@type").asText(), |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 181 | "koral:docGroup"); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 182 | assertEquals(base.at("/collection/operands/0/operands").size(), 2); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | @Test |
| 186 | public void testNodeMergeWithBase() { |
| 187 | String coll = "corpusSigle=WPD"; |
| 188 | String query = "[base=Haus]"; |
| 189 | QuerySerializer check = new QuerySerializer(); |
| 190 | check.setQuery(query, "poliqarp"); |
| 191 | check.setCollection(coll); |
| 192 | |
| 193 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 194 | b.setBaseQuery(check.toJSON()); |
| 195 | |
| 196 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 197 | test.with("textClass=wissenschaft | textClass=politik"); |
| 198 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 199 | node = b.mergeWith(node); |
| 200 | assertNotNull(node); |
| 201 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 202 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 203 | assertEquals(2, node.at("/collection/operands").size()); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | @Test |
| 208 | public void testStoredCollectionBaseQueryBuild () { |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 209 | |
| 210 | } |
| 211 | |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame^] | 212 | @Test |
| 213 | public void testAddOROperator() { |
| 214 | String coll = "corpusSigle=WPD"; |
| 215 | String query = "[base=Haus]"; |
| 216 | QuerySerializer check = new QuerySerializer(); |
| 217 | check.setQuery(query, "poliqarp"); |
| 218 | check.setCollection(coll); |
| 219 | |
| 220 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 221 | test.setBaseQuery(check.toJSON()); |
| 222 | test.or().with("textClass=wissenschaft | textClass=politik"); |
| 223 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 224 | assertNotNull(node); |
| 225 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 226 | assertEquals("operation:or", node.at("/collection/operation").asText()); |
| 227 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 228 | } |
| 229 | |
| 230 | @Test |
| 231 | public void testAddANDOperator() { |
| 232 | String coll = "corpusSigle=WPD"; |
| 233 | String query = "[base=Haus]"; |
| 234 | QuerySerializer check = new QuerySerializer(); |
| 235 | check.setQuery(query, "poliqarp"); |
| 236 | check.setCollection(coll); |
| 237 | |
| 238 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 239 | test.setBaseQuery(check.toJSON()); |
| 240 | test.and().with("textClass=wissenschaft | textClass=politik"); |
| 241 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 242 | assertNotNull(node); |
| 243 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 244 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 245 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 246 | } |
| 247 | |
| 248 | @Test |
| 249 | public void testAddDefaultOperator() { |
| 250 | String coll = "corpusSigle=WPD"; |
| 251 | String query = "[base=Haus]"; |
| 252 | QuerySerializer check = new QuerySerializer(); |
| 253 | check.setQuery(query, "poliqarp"); |
| 254 | check.setCollection(coll); |
| 255 | |
| 256 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 257 | test.setBaseQuery(check.toJSON()); |
| 258 | test.with("textClass=wissenschaft | textClass=politik"); |
| 259 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 260 | assertNotNull(node); |
| 261 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 262 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 263 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 264 | } |
| 265 | |
| 266 | @Test |
| 267 | @Ignore |
| 268 | public void testMergeOperator() { |
| 269 | String coll = "corpusSigle=WPD"; |
| 270 | String query = "[base=Haus]"; |
| 271 | QuerySerializer check = new QuerySerializer(); |
| 272 | check.setQuery(query, "poliqarp"); |
| 273 | check.setCollection(coll); |
| 274 | |
| 275 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 276 | b.setBaseQuery(check.toJSON()); |
| 277 | |
| 278 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 279 | test.with("textClass=wissenschaft | textClass=politik"); |
| 280 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 281 | node = b.mergeWith(node); |
| 282 | assertNotNull(node); |
| 283 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 284 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 285 | assertEquals(2, node.at("/collection/operands").size()); |
| 286 | } |
| 287 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 288 | } |