Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

export less data if not required

Michael Peter Christenb030188c2724
diff --git a/source/net/yacy/cora/federate/solr/responsewriter/FlatJSONResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/FlatJSONResponseWriter.java
index 9c0654c3d..2c4fb899c 100644
--- a/source/net/yacy/cora/federate/solr/responsewriter/FlatJSONResponseWriter.java
+++ b/source/net/yacy/cora/federate/solr/responsewriter/FlatJSONResponseWriter.java
@@ -158,20 +158,38 @@ public class FlatJSONResponseWriter implements QueryResponseWriter, EmbeddedSolr
JSONObject json = new JSONObject();
final Map<String, Object> fields = doc.getFieldValueMap();
SimpleDateFormat sdf=new SimpleDateFormat("YYYY-MM-DD'T'hh:mm:ssZ");
- for (String key: fields.keySet()) {
- if (key == null) continue;
- if ("_version_".equals(key)) continue;
+ fieldloop: for (String key: fields.keySet()) {
+ if (key == null) continue fieldloop;
+ if ("_version_".equals(key)) continue fieldloop;
Object value = doc.get(key);
+ if (value == null) continue fieldloop;
try {
- if (value == null) {
- } else if (value instanceof Collection<?>) {
+ if (value instanceof Collection<?>) {
+ Collection<?> fcol = (Collection<?>) value;
+ if (fcol.size() == 0) continue fieldloop;
+ if (fcol.size() == 1) {
+ Object el = fcol.iterator().next();
+ if (el instanceof String) {
+ String els = (String) el;
+ els = els.trim();
+ if (els.isEmpty()) continue fieldloop;
+ }
+ }
JSONArray a = new JSONArray();
json.put(key, a);
- for (Object o: ((Collection<?>) value)) {
+ for (Object o: fcol) {
a.put(o instanceof Date?sdf.format((Date)o):o);
}
+ } else if (value instanceof Date) {
+ Date fdate = (Date) value;
+ json.put(key, sdf.format(fdate));
+ } else if (value instanceof String) {
+ String fs = (String) value;
+ fs = fs.trim();
+ if (fs.isEmpty()) continue fieldloop;
+ json.put(key, fs);
} else {
- json.put(key, value instanceof Date?sdf.format((Date)value):value);
+ json.put(key, value);
}
} catch (JSONException | IllegalArgumentException | NullPointerException e) {
throw new IOException(e.getMessage());