Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a path #22

Closed
naxhh opened this issue Apr 26, 2012 · 6 comments
Closed

Create a path #22

naxhh opened this issue Apr 26, 2012 · 6 comments
Assignees

Comments

@naxhh
Copy link

naxhh commented Apr 26, 2012

I'm really confused with this lib.

Maybe is due of the lack of doc..

I was checking the codes and i don't come with the answer.

I have 3 nodes

node1, node2, node3

And 2 relationships
node1->node2
node2->node3

I want to get the best path from node1 to node3

But i don't know how to create a path and how to use it....

Any help?

I see a lot of nice methods in neo4j for finding best paths but seems to don't be implemented here?

My actual code can be reviewed in https://github.com/naxhh/playground/blob/master/neo4j/app.js

@aseemk
Copy link
Member

aseemk commented Apr 26, 2012

Documentation is indeed lacking -- sincere apologies. There's an issue open for better documentation: #6.

To get the shortest path from node1 to node3, use the path method on node1; here's its signature:

Node.prototype.path = function (toNode, relType, relDirection, maxDepth=1, algorithm='shortestPath', callback) {
    ...
}

At the moment, even though we have default values for maxDepth and algorithm, you still need to pass something for those parameters. It can be null though to use the default values.

So your code is close; here it is corrected:

// get the path from barcelona to reus
bcn.path(reus, 'goes', 'out', 3, null /* for shortest path */, function(err, path) {
    ...
});

Note that I corrected "from reus to barcelona" to "from barcelona to reus", as your data has the relationships going from barcelona to reus. If you really do want to get the path backwards, you can switch bcn and reus and change the direction to in or all instead of out.

Hope that helps. Sorry again for the lack of documentation, and thanks for bringing it up.

@aseemk
Copy link
Member

aseemk commented Apr 26, 2012

Btw, in general, we aren't focusing on these REST API methods much anymore, since you can achieve them with Cypher queries now. Cypher is both much simpler and much more powerful at letting you express exactly what you want.

(E.g. for shortest paths.)

But I see now that our Cypher wrapper doesn't properly handle returned paths. (Sorry, we only ever return nodes, rels and properties, so we never realized this.)

I'll leave this issue open to support paths in our Cypher wrapper. When we add this support, I'll post back here. Thanks.

@naxhh
Copy link
Author

naxhh commented Apr 26, 2012

I see.

I take a eye on the cypher doc.

Thanks for all ;)

And yes, we are working on a path-finding app so we really need that paths.

Thanks again for the quickly response.

@aseemk
Copy link
Member

aseemk commented Sep 10, 2012

Update here: returning paths in Cypher queries is now supported, in theory at least:

16a47be
1e0a795

But a quick test is still needed to confirm this.

@ghost ghost assigned aseemk Sep 11, 2012
@aseemk
Copy link
Member

aseemk commented Sep 11, 2012

Okay, added a test, fixed the code, and now indeed you can return paths in Cypher queries!

0551fb2

@aseemk aseemk closed this as completed Sep 11, 2012
@aseemk
Copy link
Member

aseemk commented Sep 11, 2012

Published to npm as v0.2.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants