Dgraph: Deep graph traversal possible with recurse?

给你一囗甜甜゛ 提交于 2021-01-27 18:51:21

问题


I have a couple of questions regarding the capabilities of Dgraph regarding graph traversal.

Let's say we have a dataset that consists of nodes of the type post. Each post can have n posts that are replies to this post. The depth of this tree is not limited.

Is it possible with Dgraph to search trough all leaf nodes starting from one starting node and return all leafs that fulfill a certain condition?

Is it possible to set a depth limit to not end up with a gigantic dataset?

Is it also possible to find the children of all parent nodes that fulfill a certain condition?

And finally: Are edges in Dgraph directed? And can I include that in the query?


回答1:


Author of Dgraph here.

Is it possible with Dgraph to search trough all leaf nodes starting from one starting node and return all leafs that fulfill a certain condition?

Yes. You could use the recurse directive (https://docs.dgraph.io/query-language/#recurse-query).

Is it possible to set a depth limit to not end up with a gigantic dataset?

Yes. Recursion supports a maximum depth.

Is it also possible to find the children of all parent nodes that fulfill a certain condition?

Yes. You can traverse an edge, and put a filter on it. https://docs.dgraph.io/query-language/#applying-filters

And finally: Are edges in Dgraph directed? And can I include that in the query?

Edges in dgraph are directed. But, Dgraph also supports a "reverse" index, which can be used to automatically generate the edges in the reverse direction. You can then traverse these reverse edges, by adding a tilde (~) in front of the predicate name.

https://docs.dgraph.io/query-language/#reverse-edges



来源:https://stackoverflow.com/questions/48895150/dgraph-deep-graph-traversal-possible-with-recurse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!