1.查询整个链路中任意一段的关系类型是“department”的链路数据
MATCH path= (n)-[r1 *0..7 {`relation_type`:'once2once'}]-(m)
where id(n)=0 and any(x in relationships(path) where type(x)='department')
return path
效果图:
2.查询整个链路中最后一段的关系类型是“”的链路数据信息
MATCH path= (n)-[r1 *0..7 {`relation_type`:'once2once'}]-(m)
where id(n)=0 and type(last(relationships(path)))='competition'
return path
效果图:
3.查询与指定节点有关联的所有关系链数据(链路存在方向)
MATCH (p)<-[r0 *0..6 {`relation_type`:'once2once'}]- (n)<-[r1 *0..6 {`relation_type`:'once2once'}]-(m)-[r2 *0..1 {`relation_type`:'many2many'}]-(o) where id(n)=%s
unwind (r0+r1+r2) as rel1
with distinct id(rel1) as id,type(rel1) as code, rel1.name as name
return code,name,count(id) as num
效果图:
4.模糊匹配节点属性包含检索字符的数据(忽略大小写)
match (n) where n:mm_yg and(n.name=~'(?i).*柴.*' or n.code=~'(?i).*柴.*' or n.dh=~'(?i).*柴.*')
RETURN n order by n.name skip 0 limit 10
效果图
5.检索节点属性是列表时的列表项值包含指定字符的数据
match (n) where n.name=~'(?i).*高.*' and any(x in n.ls where x =~'(?i).*高.*') return n;
效果图
6.查找与开始节点最近的带有指定标签的其他节点!!!
全关系图:李四的上级有组织节点,公司节点(百度科技,网易公司都是公司节点)
执行语句:
查询与李四有关系的其他节点中,最近带有有“mm_company” 标签的公司节点
(第一层 in 是循环链路中的每个节点)
(第二层 in 是循环每个节点上的每个标签,因为每个节点不止一种标签)
(第一个 all 是判断第一个节点,最后一个节点,中间节点都满足条件)
(第二个 all 是判断中间节点,必须都满足每个节点都不包含 “mm_company”标签)
MATCH path= (start)-[r *]->(end:`mm_company`)
WHERE start.name=~'(?i).*李四.*'
with start, end,nodes(path) as path
where all(x in path where (id(x)=id(start)) or (id(x)=id(end)) or (all( la in labels(x) where la<>'mm_company' ) ))
return start,end,path
效果图: