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