neo4j-core
neo4j-core copied to clipboard
No support for paths
I just wanted to find the shortest path between nodes, but unfortunately neo4j-core
doesn't map the results in this case.
p = Person.where(email: '[email protected]').first
p.query_as(:u).match("path=shortestPath(u-[:knows*]-(p: Person)), p-[:COMPANY]-(c: Company)").where("c.name = 'Company Inc.'").pluck(:path)
The result looks so:
[{:relationships=>["http://localhost:7474/db/data/relationship/313", "http://localhost:7474/db/data/relationship/327", "http://localhost:7474/db/data/relationship/329"], :nodes=>["http://localhost:7474/db/data/node/132", "http://localhost:7474/db/data/node/133", "http://localhost:7474/db/data/node/138", "http://localhost:7474/db/data/node/139"], :directions=>["<-", "<-", "->"], :length=>3, :start=>"http://localhost:7474/db/data/node/132", :end=>"http://localhost:7474/db/data/node/139"}]
Hrmm, I think we've seen this a couple of times. Definitely should be fixed, thanks!
On May 11, 2015, at 09:33, Dieter Pisarewski [email protected] wrote:
I just wanted to find the shortest path between nodes, but unfortunately neo4j-core doesn't map the results in this case.
p = Person.where(email: '[email protected]').first p.query_as(:u).match("path=shortestPath(u-[:knows*]-(p: Person)), p-[:COMPANY]-(c: Company)").where("c.name = 'Company Inc.'").pluck(:path) The result looks so:
[{:relationships=>["http://localhost:7474/db/data/relationship/313", "http://localhost:7474/db/data/relationship/327", "http://localhost:7474/db/data/relationship/329"], :nodes=>["http://localhost:7474/db/data/node/132", "http://localhost:7474/db/data/node/133", "http://localhost:7474/db/data/node/138", "http://localhost:7474/db/data/node/139"], :directions=>["<-", "<-", "->"], :length=>3, :start=>"http://localhost:7474/db/data/node/132", :end=>"http://localhost:7474/db/data/node/139"}] — Reply to this email directly or view it on GitHub.
It can use NODES(path)
to get all nodes from the path. I'm curious if it's better to implement a Path
class which could return nodes or relationships.
Yeah, I think that makes a lot of sense
On May 11, 2015, at 09:47, Dieter Pisarewski [email protected] wrote:
It can use NODES(path) to get all nodes from the path. I'm curious if it's better to implement a Path class which could return nodes or relationships.
— Reply to this email directly or view it on GitHub.
I imagine this class could also have "nodes" and "rels" methods which return just the nodes and the relationship object. Also it would be good if at least some of the code was shared between server and embedded modes. I'm currently re-implementing some functionality in embedded because I had implemented it in the server mode but didn't think about the embedded side.
I like the idea of a Path
class. @dpisarewski, what kind of behavior would you expect from it? At the least, I think we can expose each of the keys that every response provides as methods. Does it immediately load the linked nodes/rels or do they just return the IDs? Does it have an enumerator built in that lets you loop through the entire path?
One thing to also note is the resultDataContents
key for transactional statements (see: http://neo4j.com/docs/stable/rest-api-transactional.html ). We specify "row" and "REST" to get the full data out of nodes and relationships. Maybe playing with this will yield more data for paths
@subvertallchris, @cheerfulstoic Yes, I would expect methods like node
, rels
which return nodes and relationships, and each
method which will iterate over nodes and relationships together, so I would get them all by calling to_a
. I guess, it could load them immediately since I can't imagine a use case with a very long path where this could be an issue.
I've been building a new CypherSession
API in the cypher_session_reboot
branch. It's a much simpler set of modules/classes dedicated to making just cypher queries via either HTTP or Embedded (and eventually the new protocol, Bolt). This implementation has a Path
object, though the nodes/relationships, unfortunately, aren't fully populated because Neo4j doesn't give us all that data
...at least for the REST API. Embedded might be a different story