我的图表看起来像这样
A1 -> B1 & B2 & B3
A2 -> B2 & B3
A3 -> B3
A4 -> B4
如果在cypher中,我可以要求所有与 关系到给定B节点或仅其子集的A节点?
实施例
A nodes for B1 & B2 & B3 & B4 would be [A1, A2, A3, A4]
A nodes for B1 & B2 & B3 would be [A1, A2, A3]
A nodes for B2 & B3 would be [A2, A3]
A nodes for B3 would be [A3]
A nodes for B4 would be [A4]
A nodes for B1 & B2 would be []
A nodes for B2 would be []
答案 0 :(得分:1)
如果function f3() {
return Math.random() > 0.5 ? Promise.resolve(true): 'naaah'
}
f3 = f3.toString().replace(/Math\.random\(\)\s[>]\s0\.5/, function(match) {
return new Function(`return ${match}`)()
});
// here we can visually determine whether `true` or `false` is returned;
// though as vision is based on perspective, we make sure of the type
// using `RegExp` at defining `type`
console.log(f3);
// here we determine `true` or `false` using `RegExp`
let type = /return\strue/.test(f3) ? "Promise" : "String";
console.log(`f3 return type: ${type}`);
f3 = new Function(`return ${f3}`);
console.log(f3()());
个节点的B
属性值为“B1”,“B2”等,则此查询应该有效(假设包含列表的name
参数传递B节点名称字符串):
$list
答案 1 :(得分:1)
添加我的答案,该答案建立在cybersam的答案之上,但优化了索引查找(您需要:B(name)
上的索引才能利用此功能)
MATCH (a:A)-->(b:B)
WHERE b.name in $list
WITH a, COLLECT(b.name) AS bNames
WHERE ALL(n IN bNames WHERE n IN $list)
RETURN a;
这里的优点是第二行中的WHERE子句将执行索引查找:B节点并扩展到连接:A节点。换句话说,您可以立即考虑更相关的节点子集,而不是从所有连接开始:A和:B节点并过滤到WHERE ALL()
中的相关:B节点,这些节点不会使用索引。
尝试对两个查询进行分析(在添加索引之后),您应该会看到db hits的减少。