mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Merge pull request #649 from virginOne/master
Some checks failed
CI Script to build on self-hosted server / build (push) Has been cancelled
Some checks failed
CI Script to build on self-hosted server / build (push) Has been cancelled
Fix the issue of not being able to import the JSON format
This commit is contained in:
commit
accf4e424b
|
@ -22,6 +22,7 @@ package net.yacy.cora.federate.solr.responsewriter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -152,10 +153,11 @@ public class FlatJSONResponseWriter implements QueryResponseWriter, EmbeddedSolr
|
||||||
json.put(name, Double.parseDouble(value));
|
json.put(name, Double.parseDouble(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void writeDoc(final Writer writer, final SolrDocument doc) throws IOException {
|
public static final void writeDoc(final Writer writer, final SolrDocument doc) throws IOException {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
final Map<String, Object> fields = doc.getFieldValueMap();
|
final Map<String, Object> fields = doc.getFieldValueMap();
|
||||||
|
SimpleDateFormat sdf=new SimpleDateFormat("YYYY-MM-DD'T'hh:mm:ssZ");
|
||||||
for (String key: fields.keySet()) {
|
for (String key: fields.keySet()) {
|
||||||
if (key == null) continue;
|
if (key == null) continue;
|
||||||
Object value = doc.get(key);
|
Object value = doc.get(key);
|
||||||
|
@ -165,15 +167,16 @@ public class FlatJSONResponseWriter implements QueryResponseWriter, EmbeddedSolr
|
||||||
JSONArray a = new JSONArray();
|
JSONArray a = new JSONArray();
|
||||||
json.put(key, a);
|
json.put(key, a);
|
||||||
for (Object o: ((Collection<?>) value)) {
|
for (Object o: ((Collection<?>) value)) {
|
||||||
a.put(o);
|
a.put(o instanceof Date?sdf.format((Date)o):o);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
json.put(key, value);
|
json.put(key, value instanceof Date?sdf.format((Date)value):value);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException | IllegalArgumentException | NullPointerException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw new IOException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.write(json.toString());
|
writer.write(json.toString());
|
||||||
writer.write(lb);
|
writer.write(lb);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user