1
|
package eu.dnetlib.functionality.cql.lucene;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.HashMap;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
|
8
|
import com.google.common.collect.BiMap;
|
9
|
import com.google.common.collect.HashBiMap;
|
10
|
import com.google.common.collect.Lists;
|
11
|
import com.google.common.collect.Maps;
|
12
|
import eu.dnetlib.functionality.cql.CqlTranslator;
|
13
|
import eu.dnetlib.functionality.cql.CqlTranslatorImpl;
|
14
|
import eu.dnetlib.functionality.cql.CqlUtils;
|
15
|
import eu.dnetlib.functionality.cql.parse.*;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.Test;
|
18
|
import org.z3950.zing.cql.CQLNode;
|
19
|
import org.z3950.zing.cql.CQLParseException;
|
20
|
import org.z3950.zing.cql.CQLParser;
|
21
|
|
22
|
import static org.junit.Assert.assertEquals;
|
23
|
import static org.junit.Assert.assertNotNull;
|
24
|
|
25
|
public class CqlTranslatorImplTest {
|
26
|
|
27
|
private CqlTranslator translator;
|
28
|
|
29
|
private Map<String, String> weights;
|
30
|
|
31
|
@Before
|
32
|
public void setUp() {
|
33
|
translator = new CqlTranslatorImpl();
|
34
|
|
35
|
weights = Maps.newHashMap();
|
36
|
weights.put("title", "2");
|
37
|
weights.put("ugo", "1.5");
|
38
|
weights.put("tag", "3");
|
39
|
}
|
40
|
|
41
|
@Test
|
42
|
public void testToSolr_BOW() throws Exception {
|
43
|
|
44
|
String cqlQuery = "a b c";
|
45
|
String luceneQuery = translator.toLucene(cqlQuery);
|
46
|
|
47
|
printQuery(cqlQuery, luceneQuery);
|
48
|
}
|
49
|
|
50
|
@Test
|
51
|
public void testToSolr_0() throws Exception {
|
52
|
|
53
|
String cqlQuery = "\"a b x\" and r and \"eng/ita\" or f any \"pippo pluto\" and \"con: duepunti\" not (d < 5 and d > 10)";
|
54
|
String luceneQuery = translator.toLucene(cqlQuery);
|
55
|
|
56
|
printQuery(cqlQuery, luceneQuery);
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void testToSolr_00() throws Exception {
|
61
|
|
62
|
String cqlQuery = "resultdupid exact datacite____::b49fd4e3386d82df348a120cfe43516b OR objidentifier exact datacite____::b49fd4e3386d82df348a120cfe43516b";
|
63
|
String luceneQuery = translator.toLucene(cqlQuery);
|
64
|
|
65
|
printQuery(cqlQuery, luceneQuery);
|
66
|
}
|
67
|
|
68
|
@Test
|
69
|
public void testToSolr_1() throws Exception {
|
70
|
|
71
|
String cqlQuery = "publicationdate =/within \"2000-01-01 2010-01-01\"";
|
72
|
String luceneQuery = translator.toLucene(cqlQuery);
|
73
|
|
74
|
printQuery(cqlQuery, luceneQuery);
|
75
|
}
|
76
|
|
77
|
@Test
|
78
|
public void testToSolr_2() throws Exception {
|
79
|
String query = "(_all=faust AND _all=pippo) AND _all<>cinegiornale";
|
80
|
Node node = new AndNode(new AndNode(new TermNode("_all", Relation.EQUAL, "faust"), new TermNode("_all", Relation.EQUAL, "pippo")), new TermNode("_all",
|
81
|
Relation.NOT, "cinegiornale"));
|
82
|
|
83
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
84
|
|
85
|
printQuery(query, parsed.asLucene());
|
86
|
System.out.println("NODE: " + node.toLucene());
|
87
|
System.out.println("NODE: " + node.toString());
|
88
|
assertEquals(node.toLucene(), parsed.asLucene());
|
89
|
}
|
90
|
|
91
|
@Test
|
92
|
public void testToSolr_3() throws Exception {
|
93
|
String query = "_all all faust";
|
94
|
Node node = new TermNode("_all", Relation.ALL, "faust");
|
95
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
96
|
printQuery(query, parsed.asLucene());
|
97
|
assertEquals(node.toLucene(), parsed.asLucene());
|
98
|
|
99
|
query = "__all all \"caracas roma\"";
|
100
|
|
101
|
parsed = translator.getTranslatedQuery(query);
|
102
|
printQuery(query, parsed.asLucene());
|
103
|
|
104
|
query = "__all all caracas roma";
|
105
|
parsed = translator.getTranslatedQuery(query);
|
106
|
printQuery(query, parsed.asLucene());
|
107
|
|
108
|
query = "__all any caracas roma";
|
109
|
parsed = translator.getTranslatedQuery(query);
|
110
|
printQuery(query, parsed.asLucene());
|
111
|
|
112
|
query = "__all any \"caracas roma\"";
|
113
|
parsed = translator.getTranslatedQuery(query);
|
114
|
printQuery(query, parsed.asLucene());
|
115
|
|
116
|
query = "__all exact caracas roma";
|
117
|
parsed = translator.getTranslatedQuery(query);
|
118
|
printQuery(query, parsed.asLucene());
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void testToSolr_4() throws Exception {
|
123
|
|
124
|
String cqlQuery = "publicationdate =/within \"2000-01-01 2010-01-01\" and title = \"ddd\" and y < 2010 or y <= 2010 or y > 2010 or y >= 2010";
|
125
|
String luceneQuery = translator.toLucene(cqlQuery);
|
126
|
|
127
|
printQuery(cqlQuery, luceneQuery);
|
128
|
}
|
129
|
|
130
|
@Test
|
131
|
public void testToSolr_5() throws Exception {
|
132
|
|
133
|
String cqlQuery = "publicationdate within \"2000-01-01 2010-01-01\"";
|
134
|
String luceneQuery = translator.toLucene(cqlQuery);
|
135
|
|
136
|
printQuery(cqlQuery, luceneQuery);
|
137
|
}
|
138
|
|
139
|
@Test
|
140
|
public void testToSolr_6() throws Exception {
|
141
|
|
142
|
String cqlQuery = "cat sortBy title/sort.descending";
|
143
|
final TranslatedQuery tr = translator.getTranslatedQuery(cqlQuery);
|
144
|
printQuery(cqlQuery, tr.asLucene());
|
145
|
System.out.println(tr.getOptions());
|
146
|
|
147
|
}
|
148
|
|
149
|
@Test
|
150
|
public void testToSolr_7() throws Exception {
|
151
|
|
152
|
String cqlQuery = "title exact true sortBy title/sort.ascending";
|
153
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
154
|
|
155
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
156
|
|
157
|
assertNotNull(luceneQuery.getOptions().getSort().getField());
|
158
|
assertNotNull(luceneQuery.getOptions().getSort().getMode());
|
159
|
|
160
|
assertEquals("title", luceneQuery.getOptions().getSort().getField());
|
161
|
assertEquals(SortOperation.Mode.asc, luceneQuery.getOptions().getSort().getMode());
|
162
|
|
163
|
System.out.println("LUCENE: " + luceneQuery.asLucene() + " OPTIONS:" + luceneQuery.getOptions().getSort().getField() + " "
|
164
|
+ luceneQuery.getOptions().getSort().getMode());
|
165
|
|
166
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
167
|
}
|
168
|
|
169
|
@Test
|
170
|
public void testToSolr_8() throws Exception {
|
171
|
|
172
|
String cqlQuery = "__all all \"caracas - roma\"";
|
173
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
174
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
175
|
|
176
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
177
|
}
|
178
|
|
179
|
@Test
|
180
|
public void testToSolr_9() throws Exception {
|
181
|
|
182
|
String cqlQuery = "__all all \"caracas roma\"";
|
183
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
184
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
185
|
|
186
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
187
|
|
188
|
cqlQuery = "__all all caracas roma";
|
189
|
parsed = new CQLParser().parse(cqlQuery);
|
190
|
luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
191
|
|
192
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
193
|
|
194
|
cqlQuery = "__all any caracas roma";
|
195
|
parsed = new CQLParser().parse(cqlQuery);
|
196
|
luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
197
|
|
198
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
199
|
|
200
|
cqlQuery = "__all any \"caracas roma\"";
|
201
|
parsed = new CQLParser().parse(cqlQuery);
|
202
|
luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
203
|
|
204
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
205
|
|
206
|
cqlQuery = "__all exact caracas roma";
|
207
|
parsed = new CQLParser().parse(cqlQuery);
|
208
|
luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
209
|
|
210
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
211
|
}
|
212
|
|
213
|
@Test
|
214
|
public void testToSolr_10() throws Exception {
|
215
|
|
216
|
String cqlQuery = "__all all \"caracas - ro*\"";
|
217
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
218
|
|
219
|
Map<String, List<String>> cqlOptions = Maps.newHashMap();
|
220
|
BiMap<String, String> aliases = HashBiMap.create();
|
221
|
|
222
|
cqlOptions.put("wildcard", Lists.newArrayList("true"));
|
223
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap(), cqlOptions, aliases,
|
224
|
new HashMap<String, String>());
|
225
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
226
|
|
227
|
cqlOptions = Maps.newHashMap();
|
228
|
luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap(), cqlOptions, aliases, new HashMap<String, String>());
|
229
|
|
230
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
231
|
}
|
232
|
|
233
|
@Test
|
234
|
public void testToSolr_11() throws Exception {
|
235
|
|
236
|
String cqlQuery = "__all <> \"kreutz\" and __all <> \"austria\"";
|
237
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
238
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
239
|
|
240
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
241
|
}
|
242
|
|
243
|
@Test
|
244
|
public void testToSolr_12() throws Exception {
|
245
|
|
246
|
String cqlQuery = "__all <> \"kreutz\" and __all <> \"austria\" or __all <> \"italia\" and __dsid exact \"wwwww\"";
|
247
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
248
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
249
|
|
250
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
251
|
}
|
252
|
|
253
|
@Test
|
254
|
public void testToSolr_13() throws Exception {
|
255
|
|
256
|
String cqlQuery = "__all = faust and __all <> cinegiornale";
|
257
|
|
258
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
259
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
260
|
|
261
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
262
|
}
|
263
|
|
264
|
@Test
|
265
|
public void testToSolr_14() throws Exception {
|
266
|
|
267
|
String cqlQuery = "__all <> cinegiornale and __all = faust";
|
268
|
|
269
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
270
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
271
|
|
272
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
273
|
}
|
274
|
|
275
|
@Test
|
276
|
public void testToSolr_15() throws Exception {
|
277
|
|
278
|
String cqlQuery = "(asdasd or asfgqwr) and textual";
|
279
|
|
280
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
281
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(parsed, new IdentityCqlValueTransformerMap());
|
282
|
|
283
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
284
|
}
|
285
|
|
286
|
@Test
|
287
|
public void testToSolr_16() throws Exception {
|
288
|
|
289
|
String cqlQuery = "title = kreutz and subject any \"austria italy\" or tag = pippo and blabla";
|
290
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
291
|
|
292
|
Map<String, List<String>> options = Maps.newHashMap();
|
293
|
BiMap<String, String> aliases = HashBiMap.create();
|
294
|
IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
|
295
|
|
296
|
CQLNode expand = CqlUtils.expand(parsed, weights.keySet());
|
297
|
|
298
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, weights);
|
299
|
|
300
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
301
|
}
|
302
|
|
303
|
@Test
|
304
|
public void testToSolr_17() throws Exception {
|
305
|
|
306
|
String cqlQuery = "a = 1 and b = 2 or c = 3 and blabla";
|
307
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
308
|
|
309
|
Map<String, List<String>> options = Maps.newHashMap();
|
310
|
BiMap<String, String> aliases = HashBiMap.create();
|
311
|
IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
|
312
|
|
313
|
Map<String, String> w = Maps.newHashMap();
|
314
|
w.put("a", "2");
|
315
|
w.put("c", "1.5");
|
316
|
|
317
|
CQLNode expand = CqlUtils.expand(parsed, w.keySet());
|
318
|
|
319
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, w);
|
320
|
|
321
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
322
|
}
|
323
|
|
324
|
@Test
|
325
|
public void testToSolr_18() throws Exception {
|
326
|
|
327
|
String cqlQuery = "a exact 1";
|
328
|
CQLNode parsed = new CQLParser().parse(cqlQuery);
|
329
|
|
330
|
Map<String, List<String>> options = Maps.newHashMap();
|
331
|
BiMap<String, String> aliases = HashBiMap.create();
|
332
|
aliases.put("a", "b");
|
333
|
|
334
|
IdentityCqlValueTransformerMap map = new IdentityCqlValueTransformerMap();
|
335
|
|
336
|
Map<String, String> w = Maps.newHashMap();
|
337
|
|
338
|
CQLNode expand = CqlUtils.expand(parsed, w.keySet());
|
339
|
|
340
|
TranslatedQuery luceneQuery = translator.getTranslatedQuery(expand, map, options, aliases, w);
|
341
|
|
342
|
printQuery(cqlQuery, luceneQuery.asLucene());
|
343
|
}
|
344
|
|
345
|
@Test
|
346
|
public void testToSolr_19() throws Exception {
|
347
|
String query = "_all<>faust";
|
348
|
Node node = new TermNode("_all", Relation.NOT, "faust");
|
349
|
|
350
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
351
|
|
352
|
printQuery(query, parsed.asLucene());
|
353
|
assertEquals(node.toLucene(), parsed.asLucene());
|
354
|
|
355
|
query = "_all <> faust nozze";
|
356
|
// node = new TermNode("_all", Relation.NOT, "faust nozze");
|
357
|
parsed = translator.getTranslatedQuery(query);
|
358
|
printQuery(query, parsed.asLucene());
|
359
|
|
360
|
}
|
361
|
|
362
|
@Test
|
363
|
public void testToSolr_20() throws Exception {
|
364
|
|
365
|
String query = "(title = ESTUDIO and title = abierto) not (title = mediante)";
|
366
|
|
367
|
Node node = new NotNode(new AndNode(new TermNode("title", Relation.EQUAL, "ESTUDIO"), new TermNode("title", Relation.EQUAL, "abierto")), new TermNode(
|
368
|
"title", Relation.EQUAL, "mediante"));
|
369
|
|
370
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
371
|
|
372
|
printQuery(query, parsed.asLucene());
|
373
|
assertEquals(node.toLucene(), parsed.asLucene());
|
374
|
}
|
375
|
|
376
|
@Test
|
377
|
public void testToSolr_21() throws Exception {
|
378
|
|
379
|
String query = "(title = ESTUDIO and title = abierto) not (title = mediante or title = verde)";
|
380
|
|
381
|
Node node = new NotNode(new AndNode(new TermNode("title", Relation.EQUAL, "ESTUDIO"), new TermNode("title", Relation.EQUAL, "abierto")), new OrNode(
|
382
|
new TermNode("title", Relation.EQUAL, "mediante"), new TermNode("title", Relation.EQUAL, "verde")));
|
383
|
|
384
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
385
|
|
386
|
printQuery(query, parsed.asLucene());
|
387
|
assertEquals(node.toLucene(), parsed.asLucene());
|
388
|
}
|
389
|
|
390
|
@Test
|
391
|
public void testToSolr_22() throws Exception {
|
392
|
String query = " and itemtype = *";
|
393
|
// Node node = new TermNode("itemtype", Relation.EQUAL, "*");
|
394
|
|
395
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
396
|
|
397
|
printQuery(query, parsed.asLucene());
|
398
|
|
399
|
query = " AND itemtype = *";
|
400
|
parsed = translator.getTranslatedQuery(query);
|
401
|
printQuery(query, parsed.asLucene());
|
402
|
|
403
|
Map<String, List<String>> cqlOptions = Maps.newHashMap();
|
404
|
BiMap<String, String> aliases = HashBiMap.create();
|
405
|
|
406
|
cqlOptions.put("wildcard", Lists.newArrayList("true"));
|
407
|
|
408
|
query = "AND itemtype = vid* borat";
|
409
|
parsed = translator.getTranslatedQuery(query, cqlOptions);
|
410
|
printQuery(query, parsed.asLucene());
|
411
|
|
412
|
// + - && || ! ( ) { } [ ] ^ " ~ * ? : \
|
413
|
query = " AND f = * vid* bo?ra bo+ra bo-ra bo&ra bo!ra bo]ra bo^ra bo*ra";// bo|ra bo(ra bo)ra bo{ra bo}ra
|
414
|
// bo\"ra bo~ra bo:ra bo\\ra";
|
415
|
|
416
|
CQLNode cqlNode = new CQLParser().parse(query);
|
417
|
parsed = translator.getTranslatedQuery(cqlNode, new IdentityCqlValueTransformerMap(), cqlOptions, aliases, new HashMap<String, String>());
|
418
|
printQuery(query, parsed.asLucene());
|
419
|
|
420
|
parsed = translator.getTranslatedQuery(query, cqlOptions);
|
421
|
printQuery(query, parsed.asLucene());
|
422
|
|
423
|
parsed = translator.getTranslatedQuery(query);
|
424
|
printQuery(query, parsed.asLucene());
|
425
|
}
|
426
|
|
427
|
@Test
|
428
|
public void testToSolr_23() throws Exception {
|
429
|
|
430
|
String query = "_all = cat sortBy title/sort.descending";
|
431
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
432
|
|
433
|
Node node = new TermNode("_all", Relation.EQUAL, "cat");
|
434
|
|
435
|
printQuery(query, parsed.asLucene());
|
436
|
assertEquals(node.toLucene(), parsed.asLucene());
|
437
|
|
438
|
assertNotNull(parsed.getOptions().getSort().getField());
|
439
|
assertNotNull(parsed.getOptions().getSort().getMode());
|
440
|
|
441
|
assertEquals("title", parsed.getOptions().getSort().getField());
|
442
|
assertEquals(SortOperation.Mode.desc, parsed.getOptions().getSort().getMode());
|
443
|
}
|
444
|
|
445
|
@Test
|
446
|
public void testToSolr_24() throws Exception {
|
447
|
|
448
|
String query = "invalid exact true sortBy title/sort.ascending";
|
449
|
|
450
|
// Node node = new TermNode("invalid", Relation.EXACT, "true");
|
451
|
|
452
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
453
|
|
454
|
printQuery(query, parsed.asLucene());
|
455
|
|
456
|
assertNotNull(parsed.getOptions().getSort().getField());
|
457
|
assertNotNull(parsed.getOptions().getSort().getMode());
|
458
|
|
459
|
assertEquals("title", parsed.getOptions().getSort().getField());
|
460
|
assertEquals(SortOperation.Mode.asc, parsed.getOptions().getSort().getMode());
|
461
|
}
|
462
|
|
463
|
@Test
|
464
|
public void testToSolr_25() throws Exception {
|
465
|
|
466
|
// String query = "deleted all true and __dsid all xxxxxxxxxxx";
|
467
|
|
468
|
// ciao (+a +b +c)
|
469
|
String query = "ciao or (_all all \"a b c\")";
|
470
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
471
|
printQuery(query, parsed.asLucene());
|
472
|
|
473
|
query = "(__all = ciao) or (__all all \"a b c\")";
|
474
|
parsed = translator.getTranslatedQuery(query);
|
475
|
printQuery(query, parsed.asLucene());
|
476
|
|
477
|
query = "a and b";
|
478
|
parsed = translator.getTranslatedQuery(query);
|
479
|
printQuery(query, parsed.asLucene());
|
480
|
query = "field=a and field=b";
|
481
|
parsed = translator.getTranslatedQuery(query);
|
482
|
printQuery(query, parsed.asLucene());
|
483
|
|
484
|
query = "a or b";
|
485
|
parsed = translator.getTranslatedQuery(query);
|
486
|
printQuery(query, parsed.asLucene());
|
487
|
|
488
|
query = "field=a or field=b";
|
489
|
parsed = translator.getTranslatedQuery(query);
|
490
|
printQuery(query, parsed.asLucene());
|
491
|
|
492
|
query = "field all a or field all b";
|
493
|
parsed = translator.getTranslatedQuery(query);
|
494
|
printQuery(query, parsed.asLucene());
|
495
|
}
|
496
|
|
497
|
@Test
|
498
|
public void testToSolr_26() throws Exception {
|
499
|
|
500
|
String query = "publicationdate =/within \"2000-01-01 2010-01-01\"";
|
501
|
Node node = new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01");
|
502
|
|
503
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
504
|
|
505
|
printQuery(query, parsed.asLucene());
|
506
|
assertEquals(node.toLucene(), parsed.asLucene());
|
507
|
}
|
508
|
|
509
|
@Test
|
510
|
public void testToSolr_27() throws Exception {
|
511
|
|
512
|
String query = "((((publicationdate =/within \"2000-01-01 2010-01-01\" and title = \"ddd\") and y < 2010) or y <= 2010) or y > 2010) or y >= 2010";
|
513
|
Node node = new OrNode(new OrNode(new OrNode(new AndNode(new AndNode(new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01"),
|
514
|
new TermNode("title", Relation.EQUAL, "ddd")), new TermNode("y", Relation.LT, "2010")), new TermNode("y", Relation.LTE, "2010")), new TermNode(
|
515
|
"y", Relation.GT, "2010")), new TermNode("y", Relation.GTE, "2010"));
|
516
|
|
517
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
518
|
|
519
|
printQuery(query, parsed.asLucene());
|
520
|
assertEquals(node.toLucene(), parsed.asLucene());
|
521
|
}
|
522
|
|
523
|
@Test
|
524
|
public void testToSolr_28() throws Exception {
|
525
|
|
526
|
String query = "publicationdate =/within \"2000-01-01 2010-01-01\" and (title = \"ddd\" and (y < 2010 or (y <= 2010 or (y > 2010 or y >= 2010))))";
|
527
|
|
528
|
Node node = new AndNode(new TermNode("publicationdate", Relation.WITHIN, "2000-01-01 2010-01-01"), new AndNode(new TermNode("title", Relation.EQUAL,
|
529
|
"ddd"), new OrNode(new TermNode("y", Relation.LT, "2010"), new OrNode(new TermNode("y", Relation.LTE, "2010"), new OrNode(new TermNode("y",
|
530
|
Relation.GT, "2010"), new TermNode("y", Relation.GTE, "2010"))))));
|
531
|
|
532
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
533
|
|
534
|
printQuery(query, parsed.asLucene());
|
535
|
assertEquals(node.toLucene(), parsed.asLucene());
|
536
|
}
|
537
|
|
538
|
@Test
|
539
|
public void testToSolr_29() throws Exception {
|
540
|
|
541
|
String query = "dateaccepted =/within \"1900-01-01 2000-01-01\" and dateaccepted >= 2010-01-01";
|
542
|
|
543
|
Node node = new AndNode(new TermNode("dateaccepted", Relation.WITHIN, "1900-01-01 2000-01-01"),
|
544
|
new TermNode("dateaccepted", Relation.GTE, "2010-01-01"));
|
545
|
|
546
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
547
|
|
548
|
printQuery(query, parsed.asLucene());
|
549
|
assertEquals(node.toLucene(), parsed.asLucene());
|
550
|
|
551
|
query = "dateaccepted =/within \"1900-01-01 2000-01-01\" and dateaccepted > 2010-01-01";
|
552
|
|
553
|
node = new AndNode(new TermNode("dateaccepted", Relation.WITHIN, "1900-01-01 2000-01-01"), new TermNode("dateaccepted", Relation.GT, "2010-01-01"));
|
554
|
|
555
|
parsed = translator.getTranslatedQuery(query);
|
556
|
|
557
|
printQuery(query, parsed.asLucene());
|
558
|
assertEquals(node.toLucene(), parsed.asLucene());
|
559
|
}
|
560
|
|
561
|
@Test
|
562
|
public void testToSolr_30() throws Exception {
|
563
|
|
564
|
String query = "a = 1 and b = 2 and c = 3";
|
565
|
Node node = new AndNode(new AndNode(new TermNode("a", Relation.EQUAL, "1"), new TermNode("b", Relation.EQUAL, "2")), new TermNode("c", Relation.EQUAL,
|
566
|
"3"));
|
567
|
|
568
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
569
|
|
570
|
printQuery(query, parsed.asLucene());
|
571
|
assertEquals(node.toLucene(), parsed.asLucene());
|
572
|
}
|
573
|
|
574
|
@Test
|
575
|
public void testToSolr_31() throws Exception {
|
576
|
|
577
|
String query = "a = \"pippo pluto\" and b = 2 and c = 3";
|
578
|
Node node = new AndNode(new AndNode(new TermNode("a", Relation.EQUAL, "pippo pluto"), new TermNode("b", Relation.EQUAL, "2")), new TermNode("c",
|
579
|
Relation.EQUAL, "3"));
|
580
|
|
581
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
582
|
|
583
|
printQuery(query, parsed.asLucene());
|
584
|
assertEquals(node.toLucene(), parsed.asLucene());
|
585
|
}
|
586
|
|
587
|
@Test
|
588
|
public void testToSolr_32() throws Exception {
|
589
|
|
590
|
String query = "__all all \"caracas - ro*\"";
|
591
|
|
592
|
TranslatedQuery parsed = translator.getTranslatedQuery(query);
|
593
|
printQuery(query, parsed.asLucene());
|
594
|
|
595
|
Map<String, List<String>> cqlOptions = Maps.newHashMap();
|
596
|
cqlOptions.put("wildcard", Lists.newArrayList("true"));
|
597
|
|
598
|
parsed = translator.getTranslatedQuery(query, cqlOptions);
|
599
|
printQuery(query, parsed.asLucene());
|
600
|
|
601
|
}
|
602
|
|
603
|
@Test
|
604
|
public void testToSolr_33() throws Exception {
|
605
|
String query1 = "query=(deletedbyinference = false) AND (((oaftype exact project) and (test)) and (fundinglevel0_id exact corda_______::FP7))";
|
606
|
printQuery(query1, translator.getTranslatedQuery(query1).asLucene());
|
607
|
|
608
|
String query2 = "query=(((deletedbyinference = false) AND (oaftype exact project)) and (test)) and (fundinglevel0_id exact corda_______::FP7)";
|
609
|
printQuery(query2, translator.getTranslatedQuery(query2).asLucene());
|
610
|
|
611
|
String query3 = "(deletedbyinference = false) AND (((oaftype exact project) and (test)) and (fundinglevel0_id exact corda_______::FP7))";
|
612
|
printQuery(query3, translator.getTranslatedQuery(query1).asLucene());
|
613
|
|
614
|
String query4 = "(((deletedbyinference = false) AND (oaftype exact project)) and (test)) and (fundinglevel0_id exact corda_______::FP7)";
|
615
|
printQuery(query4, translator.getTranslatedQuery(query2).asLucene());
|
616
|
}
|
617
|
|
618
|
@Test
|
619
|
public void testWildcard() throws CQLParseException, IOException {
|
620
|
|
621
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
622
|
|
623
|
String cqlQuery = "__all = \"test?\"";
|
624
|
String lucene = translator.toLucene(cqlQuery, options);
|
625
|
printQuery(cqlQuery, lucene);
|
626
|
|
627
|
options.put("wildcard", Lists.newArrayList("true"));
|
628
|
|
629
|
cqlQuery = "__all = \"test?\"";
|
630
|
lucene = translator.toLucene(cqlQuery, options);
|
631
|
printQuery(cqlQuery, lucene);
|
632
|
}
|
633
|
|
634
|
@Test
|
635
|
public void testWildcard_2() throws CQLParseException, IOException {
|
636
|
|
637
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
638
|
|
639
|
String cqlQuery = "thumbnail=localhost*";
|
640
|
String lucene = translator.toLucene(cqlQuery, options);
|
641
|
printQuery(cqlQuery, lucene);
|
642
|
|
643
|
options.put("wildcard", Lists.newArrayList("true"));
|
644
|
|
645
|
lucene = translator.toLucene(cqlQuery, options);
|
646
|
printQuery(cqlQuery, lucene);
|
647
|
}
|
648
|
|
649
|
@Test
|
650
|
public void testDateQuery() throws CQLParseException, IOException {
|
651
|
String cqlQuery = "(resultdateofacceptance <= \"2012-03-15\")";
|
652
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
653
|
String lucene = translator.toLucene(cqlQuery, options);
|
654
|
printQuery(cqlQuery, lucene);
|
655
|
}
|
656
|
|
657
|
@Test
|
658
|
public void testFullISODateQuery() throws CQLParseException, IOException {
|
659
|
String cqlQuery = "(resultdateofacceptance <= 2012-03-15T00:00:00Z)";
|
660
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
661
|
String lucene = translator.toLucene(cqlQuery, options);
|
662
|
printQuery(cqlQuery, lucene);
|
663
|
}
|
664
|
|
665
|
@Test
|
666
|
public void testNonDateQuery() throws CQLParseException, IOException {
|
667
|
String cqlQuery = "(resultdateofacceptance <= 2012.03.15T00:00:00Z)";
|
668
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
669
|
String lucene = translator.toLucene(cqlQuery, options);
|
670
|
printQuery(cqlQuery, lucene);
|
671
|
}
|
672
|
|
673
|
@Test
|
674
|
public void testNonDateQuery2() throws CQLParseException, IOException {
|
675
|
String cqlQuery = "(resultdateofacceptance <= ciao)";
|
676
|
Map<String, List<String>> options = new HashMap<String, List<String>>();
|
677
|
String lucene = translator.toLucene(cqlQuery, options);
|
678
|
printQuery(cqlQuery, lucene);
|
679
|
}
|
680
|
|
681
|
@Test
|
682
|
public void testDateWrong() throws Exception {
|
683
|
|
684
|
String cqlQuery = "publicationdate =/within \"2000-01-01 2010.99.01\"";
|
685
|
String luceneQuery = translator.toLucene(cqlQuery);
|
686
|
|
687
|
printQuery(cqlQuery, luceneQuery);
|
688
|
}
|
689
|
|
690
|
@Test
|
691
|
public void testToDate() throws Exception {
|
692
|
|
693
|
String cqlQuery = "publicationdate =/within \"* 2000-01-01\"";
|
694
|
String luceneQuery = translator.toLucene(cqlQuery);
|
695
|
|
696
|
printQuery(cqlQuery, luceneQuery);
|
697
|
}
|
698
|
|
699
|
private void printQuery(final String cql, final String lucene) throws CQLParseException, IOException {
|
700
|
System.out.println("CQL: " + cql);
|
701
|
// System.out.println("PARSED: " + new CQLParser().parse(cql).toCQL());
|
702
|
System.out.println("LUCENE: " + lucene + "\n");
|
703
|
|
704
|
}
|
705
|
|
706
|
}
|