startindex replaces startPage in meta parameter
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
index a54cd46..e34610c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
@@ -6,6 +6,7 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
+import de.ids_mannheim.korap.resource.Relation;
import lombok.Data;
import java.io.IOException;
@@ -27,10 +28,6 @@
private Multimap<String, String> mextension;
- public enum RELATION {
- AND, OR
- }
-
public CollectionQuery() {
this.rq = new ArrayList<>();
this.mfilter = ArrayListMultimap.create();
@@ -60,7 +57,7 @@
return this;
}
- public CollectionQuery addMetaFilter(String queries, RELATION rel) {
+ public CollectionQuery addMetaFilter(String queries, Relation rel) {
this.mfilter.putAll(resRel(queries, rel));
return this;
}
@@ -70,15 +67,15 @@
return this;
}
- public CollectionQuery addMetaExtend(String queries, RELATION rel) {
+ public CollectionQuery addMetaExtend(String queries, Relation rel) {
this.mextension.putAll(resRel(queries, rel));
return this;
}
- private List<Map> createFilter(RELATION rel) {
- String relation = rel == RELATION.AND ? "and" : "or";
+ private List<Map> createFilter(Relation rel) {
+ String relation = rel == Relation.AND ? "and" : "or";
List<Map> mfil = new ArrayList();
boolean multypes = this.mfilter.keySet().size() > 1;
String def_key = null;
@@ -103,8 +100,8 @@
return mfil;
}
- private List<Map> createExtender(RELATION rel) {
- String relation = rel == RELATION.AND ? "and" : "or";
+ private List<Map> createExtender(Relation rel) {
+ String relation = rel == Relation.AND ? "and" : "or";
List<Map> mex = new ArrayList();
boolean multypes = this.mextension.keys().size() > 1;
String def_key = null;
@@ -127,7 +124,7 @@
return mex;
}
- private List<Map> join(RELATION filter, RELATION extension) {
+ private List<Map> join(Relation filter, Relation extension) {
List<Map> cursor = new ArrayList<>(this.rq);
if (!this.mfilter.isEmpty())
cursor.addAll(this.createFilter(filter));
@@ -212,12 +209,16 @@
return el;
}
- public List<Map> raw(RELATION filter, RELATION extension) {
+ public List<Map> raw(Relation filter, Relation extension) {
return join(filter, extension);
}
+ public List<Map> raw() {
+ return raw(Relation.AND, Relation.AND);
+ }
- public String toCollections(RELATION filter, RELATION extension) {
+
+ public String toCollections(Relation filter, Relation extension) {
Map meta = new LinkedHashMap();
meta.put("collections", join(filter, extension));
@@ -230,7 +231,7 @@
}
public String toCollections() {
- return toCollections(RELATION.AND, RELATION.AND);
+ return toCollections(Relation.AND, Relation.AND);
}
@@ -239,11 +240,11 @@
*
* @return
*/
- public JsonNode buildNode(RELATION filter, RELATION extension) {
+ public JsonNode buildNode(Relation filter, Relation extension) {
return serialzer.valueToTree(join(filter, extension));
}
- public String buildString(RELATION filter, RELATION extension) {
+ public String buildString(Relation filter, Relation extension) {
try {
return serialzer.writeValueAsString(join(filter, extension));
} catch (JsonProcessingException e) {
@@ -261,7 +262,7 @@
* @param queries
* @return
*/
- private Multimap<String, String> resRel(String queries, RELATION rel) {
+ private Multimap<String, String> resRel(String queries, Relation rel) {
Multimap<String, String> qmap = ArrayListMultimap.create();
String[] spl = queries.trim().split(rel.toString());
for (String query : spl) {
@@ -323,7 +324,7 @@
@Data
private static class Group implements Value {
- private RELATION relation;
+ private Relation relation;
private List<Term> _terms;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 9356b2d..ee0cac9 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -126,9 +126,10 @@
mapper.writeValue(new File(outFile), requestMap);
}
+ // change page to startindex
public String buildQuery(String query, String ql, String collection,
String cli, String cri, int cls, int crs,
- int num, int page, boolean cutoff, String version)
+ int num, int page, String version)
throws QueryException {
try {
if (ql.toLowerCase().equals("poliqarp")) {
@@ -153,14 +154,18 @@
Map<String, Object> requestMap = ast.getRequestMap();
+ //todo: use startindex instead
MetaQuery meta = new MetaQuery();
meta.addContext(cls, cli, crs, cri);
- meta.addEntry("cutOff", cutoff);
- meta.addEntry("startPage", page);
+// meta.addEntry("startPage", page);
+ meta.addEntry("startIndex", page);
meta.addEntry("count", num);
+ CollectionQuery qobj = new CollectionQuery();
+ qobj.addResource(collection);
+
try {
- requestMap.put("collections", collection);
+ requestMap.put("collections", qobj.raw());
requestMap.put("meta", meta.raw());
return mapper.writeValueAsString(requestMap);
} catch (IOException e) {
diff --git a/src/test/java/MetaQuerySerializationTest.java b/src/test/java/MetaQuerySerializationTest.java
index 2f7d8c3..1995510 100644
--- a/src/test/java/MetaQuerySerializationTest.java
+++ b/src/test/java/MetaQuerySerializationTest.java
@@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import de.ids_mannheim.korap.query.serialize.CollectionQuery;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
+import de.ids_mannheim.korap.resource.Relation;
import de.ids_mannheim.korap.util.QueryException;
import org.junit.Assert;
import org.junit.Test;
@@ -30,9 +31,9 @@
b.append("textClass:wissenschaft");
// CollectionQuery qu = new CollectionQuery().addMetaFilter(b.toString());
CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(),
- CollectionQuery.RELATION.AND);
- System.out.println(query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
- System.out.println(query.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ Relation.AND);
+ System.out.println(query.buildString(Relation.AND, Relation.AND));
+ System.out.println(query.toCollections(Relation.AND, Relation.AND));
// System.out.println("value reference " + qu.stringify());
// System.out.println();
}
@@ -41,7 +42,7 @@
public void testSingle() throws IOException {
CollectionQuery query = new CollectionQuery().addMetaFilter("textClass", "wissenschaft");
// System.out.println("------ TEXT SINGLE " + query.stringify());
- System.out.println(query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ System.out.println(query.buildString(Relation.AND, Relation.AND));
}
@Test
@@ -52,10 +53,10 @@
b.append("pubDate:<2012-04-01");
b.append(" AND ");
b.append("author:Goethe");
- CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), CollectionQuery.RELATION.AND);
- System.out.println("value until/since : " + query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
- System.out.println("meta value until/since " + query.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Goethe\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"between\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2012-04-01\"},{\"@type\":\"korap:date\",\"@value\":\"2013-04-01\"}]}]}}]", query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), Relation.AND);
+ System.out.println("value until/since : " + query.buildString(Relation.AND, Relation.AND));
+ System.out.println("meta value until/since " + query.toCollections(Relation.AND, Relation.AND));
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Goethe\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"between\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2012-04-01\"},{\"@type\":\"korap:date\",\"@value\":\"2013-04-01\"}]}]}}]", query.buildString(Relation.AND, Relation.AND));
// System.out.println();
}
@@ -65,9 +66,9 @@
b.append("pubDate:>2013-12-10");
b.append(" AND ");
b.append("author:Hesse");
- CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), CollectionQuery.RELATION.AND);
+ CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), Relation.AND);
System.out.println("Running date check (until) with additional attribute author");
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Hesse\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"until\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Hesse\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"until\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString(Relation.AND, Relation.AND));
// System.out.println("value until : " + query.stringify());
// System.out.println();
}
@@ -78,13 +79,13 @@
b.append("pubDate:<2013-12-10");
b.append(" AND ");
b.append("author:Kafka");
- CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), CollectionQuery.RELATION.AND);
- System.out.println("value since : " + query.buildString(CollectionQuery.RELATION.AND,
- CollectionQuery.RELATION.AND));
- System.out.println("meta value since " + query.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ CollectionQuery query = new CollectionQuery().addMetaFilter(b.toString(), Relation.AND);
+ System.out.println("value since : " + query.buildString(Relation.AND,
+ Relation.AND));
+ System.out.println("meta value since " + query.toCollections(Relation.AND, Relation.AND));
// System.out.println();
System.out.println("Running date check (since) with additional attribute author");
- Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Kafka\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"since\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ Assert.assertEquals("[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:group\",\"relation\":\"and\",\"operands\":[{\"@type\":\"korap:term\",\"@field\":\"korap:field#author\",\"@value\":\"Kafka\"},{\"@type\":\"korap:group\",\"@field\":\"korap:field#pubDate\",\"relation\":\"since\",\"operands\":[{\"@type\":\"korap:date\",\"@value\":\"2013-12-10\"}]}]}}]", query.buildString(Relation.AND, Relation.AND));
}
@Test
@@ -127,10 +128,10 @@
b.append("pubDate:<2013-12-10");
b.append(" AND ");
b.append("author:Kafka");
- CollectionQuery q = new CollectionQuery().addMetaFilter(b.toString(), CollectionQuery.RELATION.AND);
+ CollectionQuery q = new CollectionQuery().addMetaFilter(b.toString(), Relation.AND);
q.addMetaExtend("author", "Hesse");
- System.out.println("--- ALL " + q.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ System.out.println("--- ALL " + q.buildString(Relation.AND, Relation.AND));
System.out.println();
}
@@ -141,8 +142,8 @@
b.append("pubDate:<2013-12-10");
b.append(" AND ");
b.append("author:Kafka");
- CollectionQuery q = new CollectionQuery().addMetaExtend(b.toString(), CollectionQuery.RELATION.AND);
- System.out.println("array repres " + q.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ CollectionQuery q = new CollectionQuery().addMetaExtend(b.toString(), Relation.AND);
+ System.out.println("array repres " + q.buildString(Relation.AND, Relation.AND));
System.out.println();
}
@@ -151,8 +152,8 @@
CollectionQuery q = new CollectionQuery().addMetaFilter("corpusID", "A00");
q.addMetaExtend("corpusID", "A01");
- System.out.println("results stringified " + q.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
- System.out.println("results to meta" + q.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ System.out.println("results stringified " + q.buildString(Relation.AND, Relation.AND));
+ System.out.println("results to meta" + q.toCollections(Relation.AND, Relation.AND));
System.out.println();
}
@@ -167,13 +168,13 @@
String meta = "[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]";
CollectionQuery q = new CollectionQuery().addResource(meta);
System.out.println("Testing Resource Meta data");
- org.junit.Assert.assertEquals("{\"collections\":" + meta + "}", q.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ org.junit.Assert.assertEquals("{\"collections\":" + meta + "}", q.toCollections(Relation.AND, Relation.AND));
}
@Test
public void testA00() throws IOException {
CollectionQuery q = new CollectionQuery().addMetaExtend("corpusID", "A00").addMetaExtend("corpusID", "A01");
- System.out.println("A meta: " + q.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ System.out.println("A meta: " + q.buildString(Relation.AND, Relation.AND));
System.out.println();
}
@@ -182,8 +183,8 @@
String meta = "[{\"@type\":\"korap:meta-filter\",\"@value\":{\"@type\":\"korap:term\",\"@field\":\"korap:field#corpusID\",\"@value\":\"WPD\"}}]";
CollectionQuery q = new CollectionQuery().addResource(meta);
q.addMetaFilter("textClass", "wissenschaft");
- System.out.println("stringified meta " + q.buildString(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
- System.out.println("meta string " + q.toCollections(CollectionQuery.RELATION.AND, CollectionQuery.RELATION.AND));
+ System.out.println("stringified meta " + q.buildString(Relation.AND, Relation.AND));
+ System.out.println("meta string " + q.toCollections(Relation.AND, Relation.AND));
}
}