Neo4j 如何在cypher中按两个条件查找节点列表?
我有3种节点:标记、城市和地点 我想写一个包含两个列表的查询Neo4j 如何在cypher中按两个条件查找节点列表?,neo4j,cypher,Neo4j,Cypher,我有3种节点:标记、城市和地点 我想写一个包含两个列表的查询 [tag1,tag2,....] 及 我想找到一个位于这些城市之一的地方列表,并将它们从标签尽可能多的城市排序到标签较少的城市 MATCH (spot:Spot)-[:located_at]->(city:City ) where city.id IN ["22","23"] with spot as sp,city as cy MATCH (sp:Spot)-[rels:tagged_by]->(tag:T
[tag1,tag2,....]
及
我想找到一个位于这些城市之一的地方列表,并将它们从标签尽可能多的城市排序到标签较少的城市
MATCH (spot:Spot)-[:located_at]->(city:City )
where city.id IN ["22","23"]
with spot as sp,city as cy
MATCH (sp:Spot)-[rels:tagged_by]->(tag:Tag)
where tag.id IN ["16", "10151", "21"]
with sp as fsp, tag
RETURN fsp, tag, count(distinct fsp.id) AS cnt
order by cnt desc
我尝试了该查询,但不知何故无法列出节点及其标记
请帮忙!
提前谢谢 尝试子查询方法: 选择城市->查找点->查找该点的标记
MATCH (city:City)
OPTIONAL MATCH (spot:Spot)-[:located_at]->(city)
OPTIONAL MATCH (spot)-[rels:tagged_by]->(tag:Tag)
where city.id IN ["22","23"]
where tag.id IN ["16", "10151", "21"]
RETURN spot, tag, count(distinct fsp.id) AS cnt
order by cnt desc
我将如何处理这个问题是个问题
MATCH (spot:Spot)-[:located_at]->(city:City)
RETURN city,spot,size(spot-[:tagged_by]->()) as tags order by tags desc
所以现在你得到了所有标记最多的点。显然,您可以根据需要添加过滤器
MATCH (spot:Spot)-[:located_at]->(city:City) where city.name = "London"
RETURN city,spot,size(spot-[:tagged_by]->()) as tags order by tags desc
我是这样做的。我的错误是不知道如何计算关系,也不知道如何正确使用聚合
match (city:City)<-[]-(spot:Spot)
where city.id in ["22","23"]
match (spot)-[rel]->(tag:Tag)
where tag.id in ["16", "10151", "21"]
return spot, count(rel) as rel_count
order by rel_count desc limit 100
这是我想要的 这里有一个有用的链接,用于在neo4j@TomažBratanič中进行jaccard索引。我很难让带有标记的节点在这些城市中,并且它们的所有标记都在这些给定标记内。似乎我上面的代码是错误的:
match (city:City)<-[]-(spot:Spot)
where city.id in ["22","23"]
match (spot)-[rel]->(tag:Tag)
where tag.id in ["16", "10151", "21"]
return spot, count(rel) as rel_count
order by rel_count desc limit 100