【发布时间】:2017-05-24 03:19:49
【问题描述】:
现在由于 Neo4j OGM 中有一个开放的 GitHub 问题 https://github.com/neo4j/neo4j-ogm/issues/215,我必须使用以下解决方法才能将返回 @QueryResult 的 org.neo4j.ogm.session.Session.query 结果转换为此 @QueryResult 的列表:
Cypher 查询示例:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} OPTIONAL MATCH (childD)<-[:VOTED_FOR]-(vg:VoteGroup)-[:VOTED_ON]->(c:Criterion) WHERE id(c) IN {criteriaIds} WITH childD, ru, u, vg.avgVotesWeight as weight OPTIONAL MATCH (childD)<-[:SET_FOR]->(sortValue375:Value)-[:SET_ON]->(sortCharacteristic375:Characteristic) WHERE id(sortCharacteristic375) = 375 RETURN childD AS decision, ru, u, toFloat(sum(weight)) as weight, sortValue375 ORDER BY weight DESC, sortValue375.value DESC, childD.createDate DESC SKIP 0 LIMIT 1000
解决方法:
@QueryResult
public class WeightedDecision {
private Decision decision;
private Double weight;
...
}
Result queryResult = session.query(characteristicCypher, parameters);
List<WeightedDecision> weightedDecisions = new ArrayList<>();
for (Map<String, Object> result : queryResult) {
WeightedDecision weightedDecision = new WeightedDecision();
weightedDecision.setDecision((Decision) result.get("decision"));
weightedDecision.setWeight((double) result.get("weight"));
weightedDecisions.add(weightedDecision);
}
现在我必须返回 Page<WeightedDecision> 而不是 List<WeightedDecision>
如何做到这一点?请帮我更改代码以便将 queryResult 转换为 Page<WeightedDecision>
另外,如何在这个逻辑中提供countQuery?
【问题讨论】:
标签: cypher spring-data-neo4j spring-data-neo4j-4 neo4j-ogm