简体   繁体   English

如何在Neo4j中用Cypher表示此查询

[英]How represent this query with Cypher in Neo4j

I'm having some problems for solving a query in my Neo4j DB. 我在Neo4j DB中解决查询时遇到一些问题。 My DB stores info about users, songs and albums. 我的数据库存储有关用户,歌曲和专辑的信息。 A user can buy songs and albums and he can follow other users too. 用户可以购买歌曲和专辑,也可以关注其他用户。

I start from "Lisa" user. 我从“ Lisa”用户开始。 I want to find users who bought albums with same style than albums bought by Lisa but they aren't followed by Lisa (they would be recommended users for Lisa to follow them). 我想找到购买了与Lisa所购买专辑风格相同的专辑的用户,但Lisa并没有紧随他们(他们将被推荐为Lisa跟随他们的用户)。

I think that query would be similar to this but I can't find the correct sintax to represent it. 我认为查询将与此类似,但是我找不到代表它的正确正弦值。

    MATCH (me:User)-[:BOUGHT]->(a:Album)
    MATCH (other:User)-[:BOUGHT]->(a2:Album)
    WHERE NOT (me)-[:FOLLOWS]->(other) AND me.username="Lisa" 
    AND other.username <> "Lisa" AND a.style=a2.style
    RETURN other.username

Any help? 有什么帮助吗? Thanks a lot :) 非常感谢 :)

Your query works fine with this dataset. 您的查询与此数据集配合正常。 I might be misunderstanding something - can you further specify the problem? 我可能误会了一些东西-您能进一步说明问题吗?

CREATE
  (u1:User {username: "Lisa"}),
  (u2:User {username: "Louis"}),
  (a1:Album {style: "rock"}),
  (a2:Album {style: "rock"}),
  (u1)-[:BOUGHT]->(a1),
  (u2)-[:BOUGHT]->(a2)

I added some cosmetic touches to your query: 我在查询中添加了一些修饰:

MATCH (me:User {username: "Lisa"})-[:BOUGHT]->(a1:Album)
MATCH (other:User)-[:BOUGHT]->(a2:Album)
WHERE NOT (me)-[:FOLLOWS]->(other)
  AND other.username <> "Lisa"
  AND a1.style=a2.style
RETURN other.username

The result is: 结果是:

╒══════════════╕
│other.username│
╞══════════════╡
│Louis         │
└──────────────┘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM