blob: 81f6eee5173975f609ebed39d152599b95bbde3f [file] [log] [blame]
Michael Hanlf1fead42014-05-14 15:13:33 +00001import de.ids_mannheim.korap.query.serialize.CollectionQueryBuilder;
2import de.ids_mannheim.korap.query.serialize.CollectionQueryBuilder2;
3import de.ids_mannheim.korap.query.serialize.CollectionQueryTree;
4import de.ids_mannheim.korap.resource.Relation;
5import de.ids_mannheim.korap.util.QueryException;
6import de.ids_mannheim.korap.utils.JsonUtils;
7import de.ids_mannheim.korap.utils.TimeUtils;
8import org.junit.Test;
9
10public class CollectionQueryTreeTest {
11
12 CollectionQueryTree ef;
13 String map;
14 private String query;
15
16 private boolean equalsQueryContent(String res, String query) throws QueryException {
17 res = res.replaceAll(" ", "");
18 ef = new CollectionQueryTree();
19 ef.process(query);
20 String queryMap = ef.getRequestMap().get("query").toString().replaceAll(" ", "");
21 return res.equals(queryMap);
22 }
23
24 @Test
25 public void testSimple() throws QueryException {
26 query = "textClass=Sport";
27 String regex1 = "{@type=korap:filter, filter={@type=korap:term, attribute=textClass, key=Sport, match=match:eq}}";
28 ef = new CollectionQueryTree();
29 ef.process(query);
30 map = JsonUtils.toJSON(ef.getRequestMap());
31// assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
32 System.out.println("THE QUERY: " + map);
33 }
34
35
36 @Test
37 public void testComplex() throws QueryException {
38 query = "(textClass=Sport | textClass=ausland) & corpusID=WPD";
39 String regex1 = "{@type=korap:filter, filter={@type=korap:term, attribute=textClass, key=Sport, match=match:eq}}";
40 ef = new CollectionQueryTree();
41 ef.process(query);
42 map = JsonUtils.toJSON(ef.getRequestMap());
43// assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
44 System.out.println("THE QUERY 1: " + map);
45 }
46
47 @Test
48 public void testBuilder() throws QueryException {
49 CollectionQueryBuilder2 builder = new CollectionQueryBuilder2();
50 builder.setQuery("(textClass=Sport | textClass=ausland) & corpusID=WPD");
51 System.out.println("BUILDER RESULT: " + builder.toJSON());
52 }
53
54 @Test
55 public void testSimpleBuilder() {
56 CollectionQueryBuilder b = new CollectionQueryBuilder();
57 b.addMetaFilter("corpusID", "WPD");
58 b.addMetaFilter("textClass", "wissenschaft");
59 b.setFilterAttributeRelation(Relation.AND);
60 System.out.println("SIMPLE BUILDER RESULT: " + b.toCollections());
61 }
62
63 // old builder pubDate query
64 @Test
65 public void testDateQuery() {
66 CollectionQueryBuilder b = new CollectionQueryBuilder();
67 String query = "pubDate=>" + TimeUtils.getNow().getMillis();
68 query = query + " AND pubDate=<" + TimeUtils.getNow().getMillis();
69 b.addMetaFilterQuery(query);
70 b.setFilterAttributeRelation(Relation.AND);
71 System.out.println("FINAL RESOURCE: " + b.toCollections());
72 }
73
74 @Test
75 public void testDateNewQuery() throws QueryException {
76 // search for pubDate between 1990 and 2010!
77 String query = "1990<pubDate<2010 & genre=Sport";
78 CollectionQueryBuilder2 q = new CollectionQueryBuilder2();
79 q.setQuery(query);
80 System.out.println("DATE QUERY RESULT: " + q.toJSON());
81 }
82
83
84}
85