neo4j Multiple optional paths - cypher -
i'm tracking if user has liked , or voted on object in list of objects others posted.. can either likes , votes, not both. (a person can both , vote on object , these options not mutually exclusive).
to problem let me describe in relational terms (left joins used - object returned, liker , voter data returned if record of type exists)
[object]+ -> liker + -> voter
what i'd return is:
objectid likerid voterid 2343 null 88 2345 11 null 2382 44 1256 2400 null null
yet every way i've sliced cannot come out . either row 2400 skipped (i've tried every combination of where), or values shifted likerid voterid column (bug?).
here sample of cypher:
start objects=node(158) match contestant-[:posted]->object_node-[:posted_object]->objects<-[?:posted_object]-object_node_a<-[?:likes]-liker , objects<-[?:posted_object]-object_node_b<-[?:votes]-voter return id(object, id(liker), id(voter)
it doesn't work if try id(object_node_a) = id(object_node_b)...
if try liker works.. same voter.. when try both.. bombs..
i've tried using , etc never full list of objects - either trims down list based upon matches, or gives me cartesian product distinct not resolve.
sql example: left join
i'm sql guy let me explain way - have objects table on left, , want left join liker table , voter table, , return both liker id , voter id on single row along object data. object records returned regardless if there voter or liker record.
[object]+ -> liker + -> voter
is possible?
is possible via cypher?
hopefully haven't misunderstood. get
objectid likerid voterid 2343 null 88 2345 11 null 2382 44 1256 2400 null null
i.e. objects , id of liked , voted it, query should it-
start o=<lookup objects> match ul-[like?:liked]->o, uv-[vote?:voted]->o return o,id(ul),id(uv)
this return objects no votes , likes, both votes , likes , either one. note if have multiple users voting same object likely, object row repeat each user. might want like
start o=<lookup objects> match ul-[like?:liked]->o, uv-[vote?:voted]->o return o,collect(id(ul)),collect(id(uv))
to still row per object collection of user ids votes , likes.
to include person posted object well:
start o=node(4,5,6,7) match ul-[like?:liked]->o, uv-[vote?:voted]->o, c-[:posted_object]->o return o,id(ul),id(uv),id(c)
i created tiny sample play with: http://console.neo4j.org/r/in8g4w
Comments
Post a Comment