neo4j-core icon indicating copy to clipboard operation
neo4j-core copied to clipboard

No support for paths

Open dpisarewski opened this issue 9 years ago • 9 comments

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"}]

dpisarewski avatar May 11 '15 09:05 dpisarewski

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.

cheerfulstoic avatar May 11 '15 09:05 cheerfulstoic

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.

dpisarewski avatar May 11 '15 09:05 dpisarewski

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.

cheerfulstoic avatar May 11 '15 10:05 cheerfulstoic

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.

cheerfulstoic avatar May 11 '15 14:05 cheerfulstoic

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?

subvertallchris avatar May 11 '15 15:05 subvertallchris

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

cheerfulstoic avatar May 11 '15 15:05 cheerfulstoic

@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.

dpisarewski avatar May 11 '15 16:05 dpisarewski

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

cheerfulstoic avatar Sep 21 '15 01:09 cheerfulstoic

...at least for the REST API. Embedded might be a different story

cheerfulstoic avatar Sep 21 '15 01:09 cheerfulstoic