Neo4J, how to query hierarchical data / PHP -


i created category-structure in graph-database "neo4j". have nodes , relationships, perfect.

i using neoxygen neoclient php access data. how can query whole category-graph in efficient way (including structure) root-element?

match (a:`category`{category_id:0})-[r:has_child*]->(b:`category`) return b,r 

my desired structure in php is: - root --- category -------- subcategory ab --- category b --- category c -------- subcategory ca ----------------- subsubcategory caa ...

any ideas?

thanks in advance.

mr_g

it totally feasible , user-friendly in neoxygen's neoclient.

the first thing make sure, activate response formatter :

$client = clientbuilder::create()    ->setautoformatresponse(true)    ->addconnection(xxx...)    ->build(); 

secondly, concerning query set depth limit avoid memory behaviors depending of graph connectedness :

match (a:`category`{category_id:0})-[r:has_child*..20]->(b:`category`) return b,r 

then, can send client , benefit client remap results in graph structure :

$query = 'match (a:`category`{category_id:{id}})-[r:has_child*..20]->(b:`category`)' return b,r'; $children = $client->sendcypherquery($q, ['id'=>0])->getresult()->getnodes(); 

now, each node know has relationships , relationships know start , end nodes, example :

$children nodes in first depth, so

$rels = $children->getoutboundrelationships(); $nodes = []; foreach ($rels $rel) {   $nodes[] = $rel->getendnode(); } 

$nodes holds nodes in depth 2.

there is, currently, no method directly connected nodes node object without getting first relationship, maybe can add client.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -