Search in sources :

Example 1 with JsonNode

use of org.apache.tinkerpop.shaded.jackson.databind.JsonNode in project unipop by unipop-graph.

the class AbstractDocSchema method parseResults.

@Override
public List<E> parseResults(String result, PredicateQuery query) {
    List<E> results = new ArrayList<>();
    try {
        JsonNode hits = mapper.readTree(result).get("hits").get("hits");
        for (JsonNode hit : hits) {
            Map<String, Object> source = hit.has("_source") ? mapper.readValue(hit.get("_source").toString(), Map.class) : new HashMap<>();
            Document document = new Document(hit.get("_index").asText(), hit.get("_type").asText(), hit.get("_id").asText(), source);
            Collection<E> elements = fromDocument(document);
            if (elements != null) {
                elements.forEach(element -> {
                    if (element != null && query.test(element, query.getPredicates()))
                        results.add(element);
                });
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return results;
}
Also used : JsonNode(org.apache.tinkerpop.shaded.jackson.databind.JsonNode) JSONObject(org.json.JSONObject) IOException(java.io.IOException) Document(org.unipop.elastic.document.Document)

Aggregations

IOException (java.io.IOException)1 JsonNode (org.apache.tinkerpop.shaded.jackson.databind.JsonNode)1 JSONObject (org.json.JSONObject)1 Document (org.unipop.elastic.document.Document)1