tubu13
tubu13

Reputation: 934

neo4j graphity how to implement

so I have been trying for quite some time to impelement the Graphity on neo4j But i can find a way to build the queries, anyone have any leads?

for example on the neo4j document for Graphity there is a query just to get only the first element on the chain. how do i get the second one?

and also why there is an order by in the query? isn't that algorithm suppose to eliminate that?

Here is the query:

MATCH p=(me { name: 'Jane' })-[:jane_knows*]->(friend),(friend)-[:has]->(status) RETURN me.name, friend.name, status.name, length(p) ORDER BY length(p)

Upvotes: 0

Views: 67

Answers (1)

cybersam
cybersam

Reputation: 66967

[UPDATED]

That is a variable-length query (notice the * in the relationship pattern), and it gets all the elements in the chain in N result rows (where N is the length of the chain). Each result row's path will contain the previous row's path (if there was a previous row) plus the next element in the chain. And, because every row has a different path length, ordering by the path length makes sense.

If you want to see the names (in order) of all the statuses for each friend, this query should do that:

MATCH p=(me { name: 'Jane' })-[:jane_knows*]->(friend) 
WITH me, friend, LENGTH(p) AS len 
MATCH (friend)-[:has|next*]->(status) 
RETURN me.name, friend.name, COLLECT(status.name), len
ORDER BY len;

With the same data as in the linked example, the result is:

+-----------------------------------------------------+
| me.name | friend.name | COLLECT(status.name)  | len |
+-----------------------------------------------------+
| "Jane"  | "Bill"      | ["Bill_s1","Bill_s2"] | 1   |
| "Jane"  | "Joe"       | ["Joe_s1","Joe_s2"]   | 2   |
| "Jane"  | "Bob"       | ["Bob_s1"]            | 3   |
+-----------------------------------------------------+

Upvotes: 1

Related Questions