until/since values
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
index 60bd4b8..150cb5d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuerySerializer.java
@@ -19,6 +19,39 @@
public class MetaQuerySerializer {
+ private String metaString = "{\n" +
+ " \"meta\": [\n" +
+ " {\n" +
+ " \"@type\": \"korap:meta-filter\",\n" +
+ " \"@value\": {\n" +
+ " \"@type\": \"korap:group\",\n" +
+ " \"relation\": \"and\",\n" +
+ " \"operands\": [\n" +
+ " {\n" +
+ " \"@type\": \"korap:term\",\n" +
+ " \"field\": \"korap:field#author\",\n" +
+ " \"@value\": \"Goethe\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"@type\": \"korap:group\",\n" +
+ " \"field\": \"korap:field#pubDate\",\n" +
+ " \"relation\": \"between\",\n" +
+ " \"operands\": [\n" +
+ " {\n" +
+ " \"@type\": \"korap:date\",\n" +
+ " \"@value\": \"2013-12-5\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"@type\": \"korap:date\",\n" +
+ " \"@value\": \"2013-12-5\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ " }\n" +
+ " ]\n" +
+ "}";
private ObjectMapper mapper;
private MetaTypes types;
@@ -54,7 +87,6 @@
def_key = key;
if (key.contains("~") | key.contains(">") |
key.contains("<")) {
- System.out.println("values " + key);
dates.put(key, queries.get(key));
continue;
}
@@ -91,18 +123,31 @@
}
String[] proc = processDates(dates);
- int idx = 0;
+ int idx = 3;
if (proc[0] != null && proc[0].equals("r")) {
Map term1 = types.createTerm(proc[1], "korap:date");
Map term2 = types.createTerm(proc[2], "korap:date");
Map group = types.createGroup("between", "pubDate", Arrays.asList(term1, term2));
value.add(group);
- idx = 3;
}
+ if (proc[1] != null) {
+ Map term1 = types.createTerm(proc[1], "korap:date");
+ Map group = types.createGroup("since", "pubDate", Arrays.asList(term1));
+ value.add(group);
+ }
+ if (proc[2] != null) {
+ Map term1 = types.createTerm(proc[2], "korap:date");
+ Map group = types.createGroup("until", "pubDate", Arrays.asList(term1));
+ value.add(group);
+ }
+
+
for (int i = idx; i < proc.length; i++) {
- Map term = types.createTerm("pubDate", null, proc[i], "korap:date");
- value.add(term);
+ if (proc[i] != null) {
+ Map term = types.createTerm("pubDate", null, proc[i], "korap:date");
+ value.add(term);
+ }
}
@@ -137,21 +182,22 @@
//fixme: only allows for one until and since entry!!
private String[] processDates(Map<String, String> dates) {
if (dates.isEmpty())
- return new String[1];
+ return new String[3];
boolean until = false, since = false;
- String[] el = new String[dates.keySet().size() + 1];
- int idx = 1;
+ String[] el = new String[dates.keySet().size() + 3];
+ int idx = 3;
for (String key : dates.keySet()) {
if (key.contains("<")) {
since = true;
- el[1] = dates.get(key);
- }
- if (key.contains(">")) {
+ el[1] = types.formatDate(Long.valueOf(dates.get(key)), MetaTypes.YMD);
+ } else if (key.contains(">")) {
until = true;
- el[2] = dates.get(key);
- } else
- el[idx] = dates.get(key);
- idx++;
+ el[2] = types.formatDate(Long.valueOf(dates.get(key)), MetaTypes.YMD);
+ } else {
+ el[idx] = types.formatDate(Long.valueOf(dates.get(key)), MetaTypes.YMD);
+ idx++;
+ }
+
}
if (since && until)
el[0] = "r";
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index c44d036..99fb774 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -54,9 +54,28 @@
public void testDates() throws IOException {
Map<String, String> queries = new LinkedHashMap<>();
queries.put("<pubDate", String.valueOf(new DateTime().getMillis()));
- queries.put(">pubDate", String.valueOf(new DateTime().getMillis()+2));
+ queries.put(">pubDate", String.valueOf(new DateTime().getMillis() + 2));
queries.put("author", "Goethe");
String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
- System.out.println("value : "+ f);
+// System.out.println("value : "+ f);
}
+
+ @Test
+ public void testUntil() throws IOException {
+ Map<String, String> queries = new LinkedHashMap<>();
+ queries.put(">pubDate", String.valueOf(new DateTime().getMillis()));
+ queries.put("author", "Hesse");
+ String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
+ System.out.println("value until : " + f);
+ }
+
+ @Test
+ public void testSince() throws IOException {
+ Map<String, String> queries = new LinkedHashMap<>();
+ queries.put("<pubDate", String.valueOf(new DateTime().getMillis()));
+ queries.put("author", "Kafka");
+ String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
+ System.out.println("value since : " + f);
+ }
+
}