graph databases - How to realize a nested tree in Neo4j? -


I'm just starting with the Neo4j and Graph database and wondering if good use cases for nested hierarchical tree Neo4j Are there. A common example would be a nested set of comments, for example:

  - Article - Comment on article 1 - Comment on 1 comment - comment on comment 1 - Comment 3 on comment 3 - Articles 5 Comments on 5   

As I think, articles and comments will be each nodes and in every comment, parents will have relationships, articles (1 and 5) will be easy to get all the direct comments But recovering the whole set How about?

Please excuse me to use the words of the common man, I felt it is better in such a way that you are trying to use the appropriate word while confusing you all.

Using a graph database to store a tree seems perfectly appropriate for me What will best display on your data access pattern, but basically the trees will have specialization of the graph.

Yes, in your case "elements in the tree" nodes and "nesting" relationships, then here's how you can make your example:

  Create (Route: article {label: "article"}), (C1: comment {label: "comment1"}), (c1a: comment {label: "comment 1 on comment1"}), ( C1b: comment {label: "comment 1 on comment1"}}, (c1b1: comment {label: "comment 3 on comment 3"}), (c2: comment {label: "comment on article 5}"), ( Route) & lt; - [: Answer] - (c1), (c1) & lt; - [: Answer] - (c 1a), (c1) & lt; - [: Answer] - (C1b), (c1b) & lt; - [: Answer] - (C1b1), (root) & lt; - [: Answer] - (C2);   

It just creates a bunch of nodes and relationships, which imitates the structure provided to you. Here I have always chosen to use : answer to add things.

Now, "Getting everything" means only that : answer we created the relationship:

  MATCH p = (article {label} : "Article"}) & lt; - [: Answer * 1 ..] - Nodes return nodes [nodes (-2-2) nodes with nodes (P), nodes [length (nodes -1) as comments in the form of autopsy;   

This query passes through any : Answer link (starting with the root "paragraph"), then it only sees the nodes in that path, and Returns the final item ( comment and reply ) and responds to it (the other last item).

The result looks like this:

  + ------------------------- ----------- --------------------------------------- ---------- + | InResponseTo | Reply to comment | + ------------------------------------------------- ------------------------------------ + | Node [18] (label: "article"} | node [19] (label: "comment1"} | node [19] (label: "comment1"} | node [20] (label: "comment 1 comment on 2 "} | node [19] (label:" comment1 "} | node [21] (label:" comment 3 on comment 1 "} | node [21] (label:" Comment on 1 Note 3 "} | node [22] (label:" comment 3 on comment 3 "} | node [18] (label:" article "} | node [23] (label:" comment on article 5} "| + ------------------------------------------------- ------------------------------------ +   

So this

Edit - The value for which is "variable length E Path Match ", which was just a bit in the query above: One of the top 3 selling points for a graph database for me It is fine that the graphs that make DB really easy, that is, your other choices, such as relational, have scurvy painful exercises. So if you need to do such things (like here, gathering a whole tree) I will claim that a graph of DB The new argument because you are using it in its original strength.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -