[英]cypher optional match and limit
I'm looking to satisfy a particular pattern with a query and then augment it with another query starting at one of the nodes from the first query. 我正在寻找一个查询来满足特定的模式,然后从第一个查询中的一个节点开始,用另一个查询来扩充它。 I believe I can do that with a query like this:
我相信我可以通过这样的查询来做到这一点:
match (:p)-[:relationship]-(:x) optional match (:p)-[:relationship2]-(:x2) match(:p)-[:relationship]-(:x)可选match(:p)-[:relationship2]-(:x2)
Now suppose I put a limit at the end (eg Limit 200). 现在假设我在末尾设置了一个限制(例如,限制200)。 Will the rows returned exhaust all of the optional matches that are satisfied before moving onto a new primary query with a new node p?
返回的行是否将耗尽所有带有新节点p的新主查询之前满足的所有可选匹配? Or is the query liable to arbitrarily return only a subset of the optional matches?
还是查询可能会随意返回仅可选匹配项的子集?
1) Your Cypher pattern syntax seems to be bad. 1)您的Cypher模式语法似乎不好。 For a node (within parentheses) the optional identifier comes first and each optional label comes after a colon.
对于节点(在括号内),可选标识符位于最前面,每个可选标签位于冒号之后。 For a relationship (within square brackets) the optional identifier comes first and the type comes after the colon.
对于关系(在方括号内),可选标识符位于第一位,类型在冒号之后。 I suspect that your example should have looked something like this (so that the
p
identifier can be used to tie the 2 patterns together): 我怀疑您的示例应该看起来像这样(以便
p
标识符可用于将2个模式绑定在一起):
MATCH (p)-[relationship:FOO]-(x)
OPTIONAL MATCH (p)-[relationship2:BAR]-(x2)
...
2) The Cypher documentation does not define the behavior of LIMIT
to the level of detail that you are asking about, so you should craft your Cypher to get a result that is as close as reasonable to what you want. 2)Cypher文档并未将
LIMIT
的行为定义为您要询问的详细程度,因此您应精心制作Cypher,以获得与所需合理程度接近的结果。 For example, if you want to return up to 200 x2
values for a single p
found by the MATCH
pattern, you can use something like this: 例如,如果要为由
MATCH
模式找到的单个 p
返回最多200 x2
值,则可以使用如下代码:
MATCH (p)-[relationship:FOO]-(x)
WITH p LIMIT 1
OPTIONAL MATCH (p)-[relationship2:BAR]-(x2)
RETURN x2 LIMIT 200
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.