Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; |
| 5 | |
| 6 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 7 | import de.ids_mannheim.korap.util.QueryException; |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 8 | |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 9 | import org.junit.Test; |
| 10 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 11 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 12 | import com.fasterxml.jackson.databind.JsonNode; |
| 13 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 14 | |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 15 | public class CollectionQueryTreeTest { |
| 16 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 17 | String query = "foo"; |
| 18 | String ql = "poliqarpplus"; |
| 19 | String collection; |
| 20 | ArrayList<JsonNode> operands; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 21 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 22 | QuerySerializer qs = new QuerySerializer(); |
| 23 | ObjectMapper mapper = new ObjectMapper(); |
| 24 | JsonNode res; |
| 25 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 26 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 27 | public void testContext() throws QueryException, JsonProcessingException, IOException { |
| 28 | collection = "textClass=politik"; |
| 29 | String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld"; |
| 30 | qs.setQuery(query,ql); |
| 31 | qs.setCollection(collection); |
| 32 | res = mapper.readTree(qs.toJSON()); |
| 33 | assertEquals(contextString, res.get("@context").asText()); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 37 | public void testSimple() throws QueryException, JsonProcessingException, IOException { |
| 38 | collection = "textClass=politik"; |
| 39 | qs.setQuery(query,ql); |
| 40 | qs.setCollection(collection); |
| 41 | res = mapper.readTree(qs.toJSON()); |
| 42 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 43 | assertEquals("textClass", res.at("/collection/key").asText()); |
| 44 | assertEquals("politik", res.at("/collection/value").asText()); |
| 45 | assertEquals("match:eq", res.at("/collection/match").asText()); |
Joachim Bingel | 82e4ca7 | 2014-10-27 11:03:38 +0000 | [diff] [blame] | 46 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 47 | collection = "textClass!=politik"; |
| 48 | qs.setQuery(query,ql); |
| 49 | qs.setCollection(collection); |
| 50 | res = mapper.readTree(qs.toJSON()); |
| 51 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 52 | assertEquals("textClass", res.at("/collection/key").asText()); |
| 53 | assertEquals("politik", res.at("/collection/value").asText()); |
| 54 | assertEquals("match:ne", res.at("/collection/match").asText()); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 58 | public void testContains() throws QueryException, JsonProcessingException, IOException { |
| 59 | collection = "title~Mannheim"; |
| 60 | qs.setQuery(query,ql); |
| 61 | qs.setCollection(collection); |
| 62 | res = mapper.readTree(qs.toJSON()); |
| 63 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 64 | assertEquals("title", res.at("/collection/key").asText()); |
| 65 | assertEquals("Mannheim", res.at("/collection/value").asText()); |
| 66 | assertEquals("match:contains", res.at("/collection/match").asText()); |
| 67 | |
| 68 | collection = "title~\"IDS Mannheim\""; |
| 69 | qs.setQuery(query,ql); |
| 70 | qs.setCollection(collection); |
| 71 | res = mapper.readTree(qs.toJSON()); |
| 72 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 73 | assertEquals("title", res.at("/collection/key").asText()); |
| 74 | assertEquals("IDS Mannheim", res.at("/collection/value").asText()); |
| 75 | assertEquals("match:contains", res.at("/collection/match").asText()); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 79 | public void testTwoConjuncts() throws QueryException, JsonProcessingException, IOException { |
| 80 | collection = "textClass=Sport & pubDate in 2014"; |
| 81 | qs.setQuery(query,ql); |
| 82 | qs.setCollection(collection); |
| 83 | res = mapper.readTree(qs.toJSON()); |
| 84 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 85 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 86 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 87 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 88 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 89 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 90 | assertEquals("korap:doc", res.at("/collection/operands/1/@type").asText()); |
| 91 | assertEquals("pubDate", res.at("/collection/operands/1/key").asText()); |
| 92 | assertEquals("2014", res.at("/collection/operands/1/value").asText()); |
| 93 | assertEquals("type:date", res.at("/collection/operands/1/type").asText()); |
| 94 | assertEquals("match:eq", res.at("/collection/operands/1/match").asText()); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 95 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 96 | collection = "textClass=Sport & pubDate=2014"; |
| 97 | qs.setQuery(query,ql); |
| 98 | qs.setCollection(collection); |
| 99 | res = mapper.readTree(qs.toJSON()); |
| 100 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 101 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 102 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 103 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 104 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 105 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 106 | assertEquals("korap:doc", res.at("/collection/operands/1/@type").asText()); |
| 107 | assertEquals("pubDate", res.at("/collection/operands/1/key").asText()); |
| 108 | assertEquals("2014", res.at("/collection/operands/1/value").asText()); |
| 109 | assertEquals(true, res.at("/collection/operands/1/type").isMissingNode()); |
| 110 | assertEquals("match:eq", res.at("/collection/operands/1/match").asText()); |
Joachim Bingel | 3e7e2c7 | 2014-12-16 16:36:50 +0000 | [diff] [blame] | 111 | assertEquals("", res.at("/warnings/0/")); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 112 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 113 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 114 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 115 | public void testThreeConjuncts() throws QueryException, JsonProcessingException, IOException { |
| 116 | collection = "textClass=Sport & pubDate in 2014 & corpusId=WPD"; |
| 117 | qs.setQuery(query,ql); |
| 118 | qs.setCollection(collection); |
| 119 | res = mapper.readTree(qs.toJSON()); |
| 120 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 121 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 122 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 123 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 124 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 125 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 126 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 127 | assertEquals("operation:and", res.at("/collection/operands/1/operation").asText()); |
| 128 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 129 | assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText()); |
| 130 | assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText()); |
| 131 | assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText()); |
| 132 | assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText()); |
| 133 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 134 | assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText()); |
| 135 | assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText()); |
| 136 | assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText()); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 137 | } |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 138 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 139 | public void testTwoDisjuncts() throws QueryException, JsonProcessingException, IOException { |
| 140 | collection = "textClass=Sport | pubDate in 2014"; |
| 141 | qs.setQuery(query,ql); |
| 142 | qs.setCollection(collection); |
| 143 | res = mapper.readTree(qs.toJSON()); |
| 144 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 145 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 146 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 147 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 148 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 149 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 150 | assertEquals("korap:doc", res.at("/collection/operands/1/@type").asText()); |
| 151 | assertEquals("pubDate", res.at("/collection/operands/1/key").asText()); |
| 152 | assertEquals("2014", res.at("/collection/operands/1/value").asText()); |
| 153 | assertEquals("type:date", res.at("/collection/operands/1/type").asText()); |
| 154 | assertEquals("match:eq", res.at("/collection/operands/1/match").asText()); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 158 | public void testThreeDisjuncts() throws QueryException, JsonProcessingException, IOException { |
| 159 | collection = "textClass=Sport | pubDate in 2014 | corpusId=WPD"; |
| 160 | qs.setQuery(query,ql); |
| 161 | qs.setCollection(collection); |
| 162 | res = mapper.readTree(qs.toJSON()); |
| 163 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 164 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 165 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 166 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 167 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 168 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 169 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 170 | assertEquals("operation:or", res.at("/collection/operands/1/operation").asText()); |
| 171 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 172 | assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText()); |
| 173 | assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText()); |
| 174 | assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText()); |
| 175 | assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText()); |
| 176 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 177 | assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText()); |
| 178 | assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText()); |
| 179 | assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText()); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | @Test |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 183 | public void testMixed() throws QueryException, JsonProcessingException, IOException { |
| 184 | collection = "textClass=Sport | (pubDate in 2014 & corpusId=WPD)"; |
| 185 | qs.setQuery(query,ql); |
| 186 | qs.setCollection(collection); |
| 187 | res = mapper.readTree(qs.toJSON()); |
| 188 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 189 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 190 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 191 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 192 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 193 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 194 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 195 | assertEquals("operation:and", res.at("/collection/operands/1/operation").asText()); |
| 196 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 197 | assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText()); |
| 198 | assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText()); |
| 199 | assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText()); |
| 200 | assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText()); |
| 201 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 202 | assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText()); |
| 203 | assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText()); |
| 204 | assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText()); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 205 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 206 | collection = "textClass=Sport | pubDate in 2014 & corpusId=WPD"; |
| 207 | qs.setQuery(query,ql); |
| 208 | qs.setCollection(collection); |
| 209 | res = mapper.readTree(qs.toJSON()); |
| 210 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 211 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 212 | assertEquals("korap:doc", res.at("/collection/operands/0/@type").asText()); |
| 213 | assertEquals("textClass", res.at("/collection/operands/0/key").asText()); |
| 214 | assertEquals("Sport", res.at("/collection/operands/0/value").asText()); |
| 215 | assertEquals("match:eq", res.at("/collection/operands/0/match").asText()); |
| 216 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 217 | assertEquals("operation:and", res.at("/collection/operands/1/operation").asText()); |
| 218 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 219 | assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText()); |
| 220 | assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText()); |
| 221 | assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText()); |
| 222 | assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText()); |
| 223 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 224 | assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText()); |
| 225 | assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText()); |
| 226 | assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText()); |
| 227 | |
| 228 | collection = "(textClass=Sport | pubDate in 2014) & corpusId=WPD"; |
| 229 | qs.setQuery(query,ql); |
| 230 | qs.setCollection(collection); |
| 231 | res = mapper.readTree(qs.toJSON()); |
| 232 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 233 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 234 | assertEquals("korap:docGroup", res.at("/collection/operands/0/@type").asText()); |
| 235 | assertEquals("operation:or", res.at("/collection/operands/0/operation").asText()); |
| 236 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/0/@type").asText()); |
| 237 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/1/@type").asText()); |
| 238 | assertEquals("korap:doc", res.at("/collection/operands/1/@type").asText()); |
| 239 | |
| 240 | collection = "(textClass=Sport & pubDate in 2014) & corpusId=WPD"; |
| 241 | qs.setQuery(query,ql); |
| 242 | qs.setCollection(collection); |
| 243 | res = mapper.readTree(qs.toJSON()); |
| 244 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 245 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 246 | assertEquals("korap:docGroup", res.at("/collection/operands/0/@type").asText()); |
| 247 | assertEquals("operation:and", res.at("/collection/operands/0/operation").asText()); |
| 248 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/0/@type").asText()); |
| 249 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/1/@type").asText()); |
| 250 | assertEquals("korap:doc", res.at("/collection/operands/1/@type").asText()); |
| 251 | |
| 252 | collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White)"; |
| 253 | qs.setQuery(query,ql); |
| 254 | qs.setCollection(collection); |
| 255 | res = mapper.readTree(qs.toJSON()); |
| 256 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 257 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 258 | assertEquals("korap:docGroup", res.at("/collection/operands/0/@type").asText()); |
| 259 | assertEquals("operation:and", res.at("/collection/operands/0/operation").asText()); |
| 260 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 261 | assertEquals("operation:and", res.at("/collection/operands/1/operation").asText()); |
| 262 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/0/@type").asText()); |
| 263 | assertEquals("Sport", res.at("/collection/operands/0/operands/0/value").asText()); |
| 264 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/1/@type").asText()); |
| 265 | assertEquals("ausland", res.at("/collection/operands/0/operands/1/value").asText()); |
| 266 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 267 | assertEquals("WPD", res.at("/collection/operands/1/operands/0/value").asText()); |
| 268 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 269 | assertEquals("White", res.at("/collection/operands/1/operands/1/value").asText()); |
| 270 | |
| 271 | collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & pubDate in 2000)"; |
| 272 | qs.setQuery(query,ql); |
| 273 | qs.setCollection(collection); |
| 274 | res = mapper.readTree(qs.toJSON()); |
| 275 | assertEquals("korap:docGroup", res.at("/collection/@type").asText()); |
| 276 | assertEquals("operation:or", res.at("/collection/operation").asText()); |
| 277 | assertEquals("korap:docGroup", res.at("/collection/operands/0/@type").asText()); |
| 278 | assertEquals("operation:and", res.at("/collection/operands/0/operation").asText()); |
| 279 | assertEquals("korap:docGroup", res.at("/collection/operands/1/@type").asText()); |
| 280 | assertEquals("operation:and", res.at("/collection/operands/1/operation").asText()); |
| 281 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/0/@type").asText()); |
| 282 | assertEquals("Sport", res.at("/collection/operands/0/operands/0/value").asText()); |
| 283 | assertEquals("korap:doc", res.at("/collection/operands/0/operands/1/@type").asText()); |
| 284 | assertEquals("ausland", res.at("/collection/operands/0/operands/1/value").asText()); |
| 285 | assertEquals("korap:doc", res.at("/collection/operands/1/operands/0/@type").asText()); |
| 286 | assertEquals("WPD", res.at("/collection/operands/1/operands/0/value").asText()); |
| 287 | assertEquals("korap:docGroup", res.at("/collection/operands/1/operands/1/@type").asText()); |
| 288 | assertEquals("operation:and", res.at("/collection/operands/1/operands/1/operation").asText()); |
| 289 | assertEquals("White", res.at("/collection/operands/1/operands/1/operands/0/value").asText()); |
| 290 | assertEquals("2000", res.at("/collection/operands/1/operands/1/operands/1/value").asText()); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 291 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 292 | |
Joachim Bingel | 1f4c5ad | 2014-12-16 10:40:42 +0000 | [diff] [blame] | 293 | @Test |
| 294 | public void testDateYear() throws QueryException, JsonProcessingException, IOException { |
| 295 | collection = "pubDate in 2000"; |
| 296 | qs.setQuery(query,ql); |
| 297 | qs.setCollection(collection); |
| 298 | res = mapper.readTree(qs.toJSON()); |
| 299 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 300 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 301 | assertEquals("2000", res.at("/collection/value").asText()); |
| 302 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 303 | assertEquals("match:eq", res.at("/collection/match").asText()); |
| 304 | |
| 305 | collection = "pubDate = 2000"; |
| 306 | qs.setQuery(query,ql); |
| 307 | qs.setCollection(collection); |
| 308 | res = mapper.readTree(qs.toJSON()); |
| 309 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 310 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 311 | assertEquals("2000", res.at("/collection/value").asText()); |
| 312 | assertEquals(true, res.at("/collection/type").isMissingNode()); |
| 313 | assertEquals("match:eq", res.at("/collection/match").asText()); |
| 314 | |
| 315 | collection = "pubDate since 2000"; |
| 316 | qs.setQuery(query,ql); |
| 317 | qs.setCollection(collection); |
| 318 | res = mapper.readTree(qs.toJSON()); |
| 319 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 320 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 321 | assertEquals("2000", res.at("/collection/value").asText()); |
| 322 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 323 | assertEquals("match:geq", res.at("/collection/match").asText()); |
| 324 | |
| 325 | collection = "pubDate until 2000"; |
| 326 | qs.setQuery(query,ql); |
| 327 | qs.setCollection(collection); |
| 328 | res = mapper.readTree(qs.toJSON()); |
| 329 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 330 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 331 | assertEquals("2000", res.at("/collection/value").asText()); |
| 332 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 333 | assertEquals("match:leq", res.at("/collection/match").asText()); |
| 334 | } |
| 335 | |
| 336 | @Test |
| 337 | public void testDateMonthDay() throws QueryException, JsonProcessingException, IOException { |
| 338 | collection = "pubDate in 2000-02"; |
| 339 | qs.setQuery(query,ql); |
| 340 | qs.setCollection(collection); |
| 341 | res = mapper.readTree(qs.toJSON()); |
| 342 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 343 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 344 | assertEquals("2000-02", res.at("/collection/value").asText()); |
| 345 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 346 | assertEquals("match:eq", res.at("/collection/match").asText()); |
| 347 | |
| 348 | collection = "pubDate = 2000-12"; |
| 349 | qs.setQuery(query,ql); |
| 350 | qs.setCollection(collection); |
| 351 | res = mapper.readTree(qs.toJSON()); |
| 352 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 353 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 354 | assertEquals("2000-12", res.at("/collection/value").asText()); |
| 355 | assertEquals(true, res.at("/collection/type").isMissingNode()); |
| 356 | assertEquals("match:eq", res.at("/collection/match").asText()); |
| 357 | |
| 358 | collection = "pubDate since 2000-02-01"; |
| 359 | qs.setQuery(query,ql); |
| 360 | qs.setCollection(collection); |
| 361 | res = mapper.readTree(qs.toJSON()); |
| 362 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 363 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 364 | assertEquals("2000-02-01", res.at("/collection/value").asText()); |
| 365 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 366 | assertEquals("match:geq", res.at("/collection/match").asText()); |
| 367 | |
| 368 | collection = "pubDate until 2000-01-01"; |
| 369 | qs.setQuery(query,ql); |
| 370 | qs.setCollection(collection); |
| 371 | res = mapper.readTree(qs.toJSON()); |
| 372 | assertEquals("korap:doc", res.at("/collection/@type").asText()); |
| 373 | assertEquals("pubDate", res.at("/collection/key").asText()); |
| 374 | assertEquals("2000-01-01", res.at("/collection/value").asText()); |
| 375 | assertEquals("type:date", res.at("/collection/type").asText()); |
| 376 | assertEquals("match:leq", res.at("/collection/match").asText()); |
| 377 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 378 | } |
| 379 | |