Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 2 | import de.ids_mannheim.korap.query.serialize.CollectionQueryTree; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 3 | import de.ids_mannheim.korap.util.QueryException; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 4 | import org.junit.Test; |
| 5 | |
| 6 | public class CollectionQueryTreeTest { |
| 7 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 8 | CollectionQueryTree cqt; |
| 9 | String map; |
| 10 | private String query; |
| 11 | private String expected; |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 12 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 13 | @Test |
| 14 | public void testSimple() throws QueryException { |
| 15 | query = "textClass=Sport"; |
| 16 | // String regex1 = "{@type=korap:filter, filter={@type=korap:doc, attribute=textClass, key=Sport, match=match:eq}}"; |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 17 | expected = "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 18 | cqt = new CollectionQueryTree(); |
| 19 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 20 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 21 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 22 | |
| 23 | query = "textClass!=Sport"; |
| 24 | // String regex1 = "{@type=korap:filter, filter={@type=korap:doc, attribute=textClass, key=Sport, match=match:eq}}"; |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 25 | expected = "{@type=korap:doc, key=textClass, value=Sport, match=match:ne}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 26 | cqt = new CollectionQueryTree(); |
| 27 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 28 | map = cqt.getRequestMap().get("collection").toString(); |
| 29 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 30 | } |
| 31 | |
| 32 | @Test |
| 33 | public void testContains() throws QueryException { |
| 34 | query = "title~Mannheim"; |
| 35 | expected = |
| 36 | "{@type=korap:doc, key=title, value=Mannheim, match=match:contains}"; |
| 37 | cqt = new CollectionQueryTree(); |
| 38 | cqt.process(query); |
| 39 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 40 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testTwoConjuncts() throws QueryException { |
| 45 | query = "textClass=Sport & year=2014"; |
| 46 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 47 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 48 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 49 | "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 50 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 51 | cqt = new CollectionQueryTree(); |
| 52 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 53 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 54 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testThreeConjuncts() throws QueryException { |
| 59 | query = "textClass=Sport & year=2014 & corpusID=WPD"; |
| 60 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 61 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 62 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 63 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 64 | "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}," + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 65 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" + |
| 66 | "]}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 67 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 68 | cqt = new CollectionQueryTree(); |
| 69 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 70 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 71 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | @Test |
| 76 | public void testTwoDisjuncts() throws QueryException { |
| 77 | query = "textClass=Sport | year=2014"; |
| 78 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 79 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 80 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 81 | "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 82 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 83 | cqt = new CollectionQueryTree(); |
| 84 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 85 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 86 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testThreeDisjuncts() throws QueryException { |
| 91 | query = "textClass=Sport | year=2014 | corpusID=WPD"; |
| 92 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 93 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 94 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 95 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 96 | "{@type=korap:doc, key=year, type=type:date, value=2014, match=match:eq}," + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 97 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" + |
| 98 | "]}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 99 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 100 | cqt = new CollectionQueryTree(); |
| 101 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 102 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 103 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 104 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 105 | |
| 106 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 107 | @Test |
| 108 | public void testMixed() throws QueryException { |
| 109 | query = "(textClass=Sport | textClass=ausland) & corpusID=WPD"; |
| 110 | expected = |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 111 | |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 112 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
| 113 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 114 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
| 115 | "{@type=korap:doc, key=textClass, value=ausland, match=match:eq}" + |
| 116 | "]}," + |
| 117 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 118 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 119 | cqt = new CollectionQueryTree(); |
| 120 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 121 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 122 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 123 | |
| 124 | query = "(textClass=Sport & textClass=ausland) & corpusID=WPD"; |
| 125 | expected = |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 126 | |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 127 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
| 128 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 129 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
| 130 | "{@type=korap:doc, key=textClass, value=ausland, match=match:eq}" + |
| 131 | "]}," + |
| 132 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 133 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 134 | cqt = new CollectionQueryTree(); |
| 135 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 136 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 137 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 138 | |
| 139 | query = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White)"; |
| 140 | expected = |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 141 | |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 142 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
| 143 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 144 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
| 145 | "{@type=korap:doc, key=textClass, value=ausland, match=match:eq}" + |
| 146 | "]}," + |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 147 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 148 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}," + |
| 149 | "{@type=korap:doc, key=author, value=White, match=match:eq}" + |
| 150 | "]}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 151 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 152 | cqt = new CollectionQueryTree(); |
| 153 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 154 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 155 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 156 | |
| 157 | query = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & year=2010)"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 158 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 159 | "{@type=korap:docGroup, operation=operation:or, operands=[" + |
| 160 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 161 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
| 162 | "{@type=korap:doc, key=textClass, value=ausland, match=match:eq}" + |
| 163 | "]}," + |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 164 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 165 | "{@type=korap:doc, key=corpusID, value=WPD, match=match:eq}," + |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 166 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 167 | "{@type=korap:doc, key=author, value=White, match=match:eq}," + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 168 | "{@type=korap:doc, key=year, type=type:date, value=2010, match=match:eq}" + |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 169 | "]}" + |
| 170 | "]}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 171 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 172 | cqt = new CollectionQueryTree(); |
| 173 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 174 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 175 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 176 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 177 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 178 | @Test |
| 179 | public void testDate() throws QueryException { |
| 180 | // search for pubDate between 1990 and 2010! |
| 181 | query = "1990<pubDate<2010"; |
| 182 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 183 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 184 | "{@type=korap:doc, key=pubDate, type=type:date, value=1990, match=match:gt}," + |
| 185 | "{@type=korap:doc, key=pubDate, type=type:date, value=2010, match=match:lt}" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 186 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 187 | cqt = new CollectionQueryTree(); |
| 188 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 189 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 190 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 191 | |
| 192 | query = "pubDate>=1990"; |
| 193 | expected = |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 194 | "{@type=korap:doc, key=pubDate, type=type:date, value=1990, match=match:geq}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 195 | cqt = new CollectionQueryTree(); |
| 196 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 197 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 198 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 199 | |
| 200 | query = "pubDate>=1990-05"; |
| 201 | expected = |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 202 | "{@type=korap:doc, key=pubDate, type=type:date, value=1990-05, match=match:geq}"; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 203 | cqt = new CollectionQueryTree(); |
| 204 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 205 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 206 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 207 | |
| 208 | query = "pubDate>=1990-05-01"; |
| 209 | expected = |
Joachim Bingel | 49da7ca | 2014-10-07 12:26:14 +0000 | [diff] [blame] | 210 | "{@type=korap:doc, key=pubDate, type=type:date, value=1990-05-01, match=match:geq}"; |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 211 | cqt = new CollectionQueryTree(); |
| 212 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 213 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 624854b | 2014-07-23 13:53:28 +0000 | [diff] [blame] | 214 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 215 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 216 | |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 217 | @Test |
| 218 | public void testRegex() throws QueryException { |
| 219 | query = "author=/Go.*he/"; |
| 220 | expected = |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 221 | "{@type=korap:doc, key=author, value=Go.*he, type=type:regex, match=match:eq}"; |
| 222 | cqt = new CollectionQueryTree(); |
| 223 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 224 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 225 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 226 | } |
| 227 | |
| 228 | @Test |
| 229 | public void testContentFilter() throws QueryException { |
| 230 | query = "[base=Schwalbe]"; |
| 231 | expected = |
| 232 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schwalbe, match=match:eq}}"; |
| 233 | cqt = new CollectionQueryTree(); |
| 234 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 235 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 236 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 237 | |
| 238 | query = "[cnx/base=Schwalbe]"; |
| 239 | expected = |
| 240 | "{@type=korap:token, wrap={@type=korap:term, foundry=cnx, layer=lemma, key=Schwalbe, match=match:eq}}"; |
| 241 | cqt = new CollectionQueryTree(); |
| 242 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 243 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 244 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 245 | |
| 246 | query = "[base!=Schwalbe]"; |
| 247 | expected = |
| 248 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schwalbe, match=match:ne}}"; |
| 249 | cqt = new CollectionQueryTree(); |
| 250 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 251 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 252 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 253 | |
| 254 | query = "[base=Schwalbe] & [orth=Foul]"; |
| 255 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 256 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 257 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schwalbe, match=match:eq}}," + |
| 258 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Foul, match=match:eq}}" + |
| 259 | "]}"; |
| 260 | cqt = new CollectionQueryTree(); |
| 261 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 262 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 263 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 264 | } |
| 265 | |
| 266 | @Test |
| 267 | public void testContentMetaMixed() throws QueryException { |
| 268 | query = "textClass=Sport & [base=Schwalbe]"; |
| 269 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 270 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 271 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}," + |
| 272 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schwalbe, match=match:eq}}" + |
| 273 | "]}"; |
| 274 | cqt = new CollectionQueryTree(); |
| 275 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 276 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 277 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 278 | |
| 279 | query = "[base=Schwalbe] & textClass=Sport"; |
| 280 | expected = |
Joachim Bingel | b895c1f | 2014-09-29 09:31:05 +0000 | [diff] [blame] | 281 | "{@type=korap:docGroup, operation=operation:and, operands=[" + |
Joachim Bingel | 43a444a | 2014-08-07 15:06:02 +0000 | [diff] [blame] | 282 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schwalbe, match=match:eq}}," + |
| 283 | "{@type=korap:doc, key=textClass, value=Sport, match=match:eq}" + |
| 284 | "]}"; |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 285 | cqt = new CollectionQueryTree(); |
| 286 | cqt.process(query); |
Joachim Bingel | a499e92 | 2014-10-08 13:32:50 +0000 | [diff] [blame] | 287 | map = cqt.getRequestMap().get("collection").toString(); |
Joachim Bingel | a3f51f7 | 2014-07-22 14:45:31 +0000 | [diff] [blame] | 288 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 289 | } |
Michael Hanl | f1fead4 | 2014-05-14 15:13:33 +0000 | [diff] [blame] | 290 | |
| 291 | } |
| 292 | |