Fixed pubDate bug
diff --git a/src/main/java/de/ids_mannheim/korap/KorapCollection.java b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
index 6c33c7c..1f65da2 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapCollection.java
@@ -11,6 +11,7 @@
import de.ids_mannheim.korap.KorapFilter;
import de.ids_mannheim.korap.util.KorapDate;
+import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.filter.BooleanFilter;
import de.ids_mannheim.korap.filter.FilterOperation;
import org.apache.lucene.search.spans.SpanQuery;
@@ -58,6 +59,7 @@
try {
JsonNode json = mapper.readValue(jsonString, JsonNode.class);
if (json.has("meta")) {
+ log.trace("Add meta collection");
for (JsonNode meta : json.get("meta")) {
this.fromJSON(meta);
};
@@ -72,13 +74,15 @@
this.filter = new ArrayList<FilterOperation>(5);
};
- public void fromJSON(JsonNode json) {
+ public void fromJSON(JsonNode json) throws QueryException {
String type = json.get("@type").asText();
if (type.equals("korap:meta-filter")) {
+ log.trace("Add Filter");
this.filter(new BooleanFilter(json.get("@value")));
}
else if (type.equals("korap:meta-extend")) {
+ log.trace("Add Extend");
this.extend(new BooleanFilter(json.get("@value")));
};
};
@@ -134,6 +138,14 @@
};
+ public String toString () {
+ StringBuffer sb = new StringBuffer();
+ for (FilterOperation fo : this.filter) {
+ sb.append(fo.toString()).append("; ");
+ };
+ return sb.toString();
+ };
+
// DEPRECATED BUT USED IN TEST CASES
public KorapResult search (SpanQuery query) {
return this.index.search(this, query, 0, (short) 20, true, (short) 5, true, (short) 5);
@@ -231,5 +243,9 @@
return this.index.numberOf(this, "tokens", type);
};
+ public String getError () {
+ return this.error;
+ };
+
// implement "till" with rangefilter
};
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
index 8733a38..4f55dd0 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
@@ -252,6 +252,8 @@
public KorapSearch setCollection (KorapCollection kc) {
this.collection = kc;
+ if (kc.getError() != null)
+ this.error = kc.getError();
return this;
};
diff --git a/src/main/java/de/ids_mannheim/korap/filter/BooleanFilter.java b/src/main/java/de/ids_mannheim/korap/filter/BooleanFilter.java
index 5a22198..b9bf69d 100644
--- a/src/main/java/de/ids_mannheim/korap/filter/BooleanFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/filter/BooleanFilter.java
@@ -17,6 +17,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.util.QueryException;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,18 +40,19 @@
private String type;
// Logger
- private final static Logger jlog = LoggerFactory.getLogger(KorapFilter.class);
-
+ private final static Logger log = LoggerFactory.getLogger(KorapFilter.class);
private BooleanQuery bool;
+ private String error;
public BooleanFilter () {
bool = new BooleanQuery();
};
- public BooleanFilter (JsonNode json) {
+ public BooleanFilter (JsonNode json) throws QueryException {
bool = new BooleanQuery();
-
+ this.fromJSON(json, "tokens");
+ /*
String type = json.get("@type").asText();
String field = _getField(json);
@@ -62,12 +65,15 @@
this.fromJSON(operand, field);
};
};
+ */
};
- private void fromJSON (JsonNode json, String field) {
+ private void fromJSON (JsonNode json, String field) throws QueryException {
String type = json.get("@type").asText();
+ log.trace("@type: " + type);
+
if (json.has("@field"))
field = _getField(json);
@@ -82,7 +88,10 @@
String date, till;
+ log.trace("relation: " + json.get("relation").asText());
+
switch (json.get("relation").asText()) {
+
case "between":
date = _getDate(json, 0);
till = _getDate(json, 1);
@@ -107,8 +116,23 @@
if (date != null)
this.date(date);
break;
+
+ case "and":
+ if (!json.has("operands"))
+ return;
+
+ for (JsonNode operand : json.get("operands")) {
+ this.fromJSON(operand, field);
+ };
+ break;
+
+ default:
+ throw new QueryException(json.get("relation").asText() + " is not a supported relation");
};
}
+ else {
+ throw new QueryException(type + " is not a supported group");
+ };
};
private static String _getField (JsonNode json) {
@@ -232,7 +256,7 @@
);
}
catch (NumberFormatException e) {
- jlog.warn("Parameter of till(date) is invalid");
+ log.warn("Parameter of till(date) is invalid");
};
return this;
};
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index e050a57..addc5d8 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -11,7 +11,8 @@
#log4j.logger.de.ids_mannheim.korap.query.spans.MatchSpans = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.KorapIndex = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.KorapMatch = TRACE, stdout
-# log4j.logger.de.ids_mannheim.korap.KorapCollection = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.KorapFilter = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.KorapCollection = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.index.PositionsToOffset = TRACE, stdout
# log4j.logger.de.ids_mannheim.korap.analysis.MultiTermTokenStream = TRACE, stdout