gremlin - 查找节点结果集的所有边
问题描述
我有一个返回一组节点的查询,如下所示:
g.V().as("a","node").has("prop1", true).out().as("b","node").hasLabel("device")
.in().as("c","node").hasLabel("lbl1").has("prop1", false).select("a","b","c").limit(200)
现在我想返回所有这些节点以及它们之间的任何边缘作为我的结果。我尝试了以下方法,但它总是空空如也:
g.V().(....)
.select("a","b","c").limit(200)
.select("node").dedup().fold().as('all')
.unfold().as('start').bothE().as('edge').otherV().as('end')
.where(within('all'))
.select('start', 'edge', 'end').dedup()
不幸的是,这总是空的。我认为我的 where 过滤器不正确。如何仅过滤那些节点“c”是“a”中的节点之一的结果?
我想保持这个通用性,这样我就可以用它来处理多个不同的查询,这些查询都返回一组节点。
解决方案
对于此查询,您应该检查 out 顶点是否在开始顶点的集合中。因此,您应该首先 fold() 开始集,然后在其中使用 within() 谓词对其进行检查,例如这里是查询g = TinkerFactory.createModern().traversal()
g.V().limit(3).fold().as('all').
unfold().as('a').outE().as('b').otherV().as('c').
where(within('all')).
select('a', 'b', 'c')
请参阅此处的第二个示例:https ://tinkerpop.apache.org/docs/current/reference/#where-step
推荐阅读
- merge - 将合并冲突导出为 Excel 文件
- airflow - Airflow 中的临时跳过任务
- linux - 无法通过 ssh 将 netstat、scp 命令运行到 bash shell 中的另一台主机
- python - 从 PDF 中提取文本并与字典进行比较
- mysql - MySQL评级表优化
- c++ - 编写接受 cv::Mat 或 cv::UMat 类型输入的模板函数
- css - 我对模态对话框 css 和 angular 5 有问题
- c# - 覆盖 ASP.NET Core ResourceFilter 中的 BadRequest 响应
- c# - FluentValidation - 无代码重复的预验证/条件验证
- bash - Debian 9 上的套接字问题 - 如何使用 bash 脚本进行检查