用于匹配关系的datetime属性的Cypher查询



我有一个具有以下模式的图。

(a:Person)-[:MET {at:meeting_datetime}]-(b:Person)

CCD_ 2和CCD_ 3之间可能存在多个CCD_。我需要找到我的图的子图,在这些子图中,所有人都在紧随其后的时间(一个小时(会面。一种方法是使用

MATCH (a:Person)-[a_b_met]-(b:Person)
CALL apoc.path.subgraphAll(a, {
relationshipFilter: "MET",
minLevel: 1

})
YIELD nodes, relationships
WITH nodes, relationships
UNWIND relationships as relationship
WITH relationship
MATCH (a)-[relationship]-(b)
WHERE duration.between(relationship.at, a_b_met.at).months = 0 
AND duration.between(relationship.at, a_b_met.at).days = 0 
AND abs(duration.between(relationship.at, a_b_met.at).seconds) < 3600
RETURN a,b

但这在计算方面是昂贵的,因为在用at属性对所有可能的MET路径进行过滤之前,我会匹配它们。有更好的方法吗?

编辑:上面的代码不起作用,因为没有为WHERE子句定义a_b_met

最后,这是合理的。但现在我有了一个上限,可以跟踪大约在同一时间会面的人数。

MATCH (a:Person)-[a_b_met:MET]-(b:Person) 
OPTIONAL MATCH (b)-[b_c_met:MET]-(c:Person)
WHERE duration.between(b_c_met.at, a_b_met.at).days = 0 AND duration.between(b_c_met.at, a_b_met.at).months = 0 AND abs(duration.between(b_c_met.at, a_b_met.at).seconds) < 3600 AND c<>a
OPTIONAL MATCH (c)-[c_d_met:MET]-(d:Person)
WHERE duration.between(c_d_met.at, a_b_met.at).days = 0 AND duration.between(c_d_met.at, a_b_met.at).months = 0 AND abs(duration.between(c_d_met.at, a_b_met.at).seconds) < 3600 AND d<>a AND d<>b
RETURN a,a_b_met,b,b_c_met,c,c_d_met,d

我将时间的表示形式更改为单个数字,然后这给出了一些合理的结果:

MATCH path = (a:Person)-[:MET*]->(b:Person)
WHERE a<>b AND length(path)>1 AND apoc.coll.max([rel in relationships(path)| rel.at]) - apoc.coll.min([rel in relationships(path)| rel.at]) < 3600
RETURN ([nd in nodes(path)|nd.name])

我试过

MATCH path = (a:Person)-[:MET*]-(b:Person) 
WHERE duration.between(apoc.coll.max([rel in relationships(path)| rel.at]), apoc.coll.min([rel in relationships(path)| rel.at])).days = 0
AND 
duration.between(apoc.coll.max([rel in relationships(path)| rel.at]), apoc.coll.min([rel in relationships(path)| rel.at])).months = 0 
AND 
duration.between(apoc.coll.max([rel in relationships(path)| rel.at]), apoc.coll.min([rel in relationships(path)| rel.at])).seconds < 3600
RETURN path

它非常慢。

最新更新