Returning the entire hierarchy (tree) with neo4j / cypher

I have a chart in which there is a hierarchy of categories (for example, categories of goods on a trading site, for example, clothes → men’s → shirts → short-sleeved → ...). I have several cases where I need to get the whole hierarchy in the form of a tree (nested ruby ​​and / or javascript objects in this case). The only solution I could come up with is to use NODES()each unique path to extract and then convert it to nested objects on the client. Doing this is obviously a problem.

MATCH (store:Store),
      (store)-[:hasCategory]->(category:Category),
      categories=(category)-[:narrower*0..]->(:Category)
WHERE store.name = {name}
RETURN store, NODES(categories) AS categories

This returns rows of results, which are basically the following paths:

[store, [category1, narrower_category1, narrower_category2, ...]]

What is the right way to handle this in cypher without numerous trips to the server or a massive selection of data like the above query?

+2
source share
1 answer

What is the right way to handle this in cypher without numerous trips back to the server or a massive selection of data like the above query?

If you have a large hierarchy, you will have two main options: get several levels of the hierarchy at a time (which will require trips to the server to get the next fragment), or you can get everything as you do. I do not see the third option, so it may not be possible to get a large hierarchy without any of these functions.

, , , . , ? ? . , . ( , , ). , "", ( "E-book reader", "computer" ..). , IMHO - , . , AJAX -. , AJAX- .

, , :

MATCH (category:Category { id: "whatever user picked" })-[:narrower]->(children:Category)
RETURN children
ORDER BY children.name;

( ) , , " ".

+3

Source: https://habr.com/ru/post/1614874/


All Articles