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