Neo4j Cypher query sort order -
in neo4j/sdn project have following mode:
decision
entity contains child decision
, characteristic
entities.
each pair of child decision
, characteristic
can have value node assigned.
i have created 3 child decision
nodes, example
childdecision1 childdecision2 childdecision3
and 1 characteristic
:
characterisitc1
i have assigned following values following pairs:
childdecision2 + characterisitc1 = value(integer 10) childdecision3 + characterisitc1 = value(integer 25)
i'm executing following cypher query(with order sortvalue88.value asc
):
match (parentd)-[:contains]->(childd:decision)-[ru:created_by]->(u:user) id(parentd) = {decisionid} optional match (childd)<-[:set_for]->(sortvalue88:value)-[:set_on]->(sortcharacteristic88:characteristic) id(sortcharacteristic88) = 88 ru, u, childd , sortvalue88 order sortvalue88.value asc skip 0 limit 100 return ru, u, childd decision, [ (parentd)<-[:defined_by]-(entity)<-[:commented_on]-(comg:commentgroup)-[:commented_for]->(childd) | {entityid: id(entity), types: labels(entity), totalcomments: toint(comg.totalcomments)} ] commentgroups, [ (parentd)<-[:defined_by]-(c1:criterion)<-[:voted_on]-(vg1:votegroup)-[:voted_for]->(childd) | {criterionid: id(c1), weight: vg1.avgvotesweight, totalvotes: toint(vg1.totalvotes)} ] weightedcriteria, [ (parentd)<-[:defined_by]-(ch1:characteristic)<-[:set_on]-(v1:value)-[:set_for]->(childd) | {characteristicid: id(ch1), value: v1.value, valuetype: ch1.valuetype, visualmode: ch1.visualmode} ] valuedcharacteristics
as result have:
childdecision2 (value = 10) childdecision3 (value = 25) childdecision1 (no value provided)
so far works fine.
right i'm going change sort order direction asc
desc
:
match (parentd)-[:contains]->(childd:decision)-[ru:created_by]->(u:user) id(parentd) = {decisionid} optional match (childd)<-[:set_for]->(sortvalue88:value)-[:set_on]->(sortcharacteristic88:characteristic) id(sortcharacteristic88) = 88 ru, u, childd , sortvalue88 order sortvalue88.value desc skip 0 limit 100 return ru, u, childd decision, [ (parentd)<-[:defined_by]-(entity)<-[:commented_on]-(comg:commentgroup)-[:commented_for]->(childd) | {entityid: id(entity), types: labels(entity), totalcomments: toint(comg.totalcomments)} ] commentgroups, [ (parentd)<-[:defined_by]-(c1:criterion)<-[:voted_on]-(vg1:votegroup)-[:voted_for]->(childd) | {criterionid: id(c1), weight: vg1.avgvotesweight, totalvotes: toint(vg1.totalvotes)} ] weightedcriteria, [ (parentd)<-[:defined_by]-(ch1:characteristic)<-[:set_on]-(v1:value)-[:set_for]->(childd) | {characteristicid: id(ch1), value: v1.value, valuetype: ch1.valuetype, visualmode: ch1.visualmode} ] valuedcharacteristics
as result have:
childdecision1 (no value provided) childdecision3 (value = 25) childdecision2 (value = 10)
right don't understand why childdecision1 hold first place expect childdecision3 instead there.
could please explain/fix behavior ?
so need know minimum possible value sorting. example, if values not less zero
with [1, 0, 2, null, 4] cs unwind range(0, size(cs)-1) return i, case when cs[i] null -1 else cs[i] end sortvalue order sortvalue desc
Comments
Post a Comment