简体   繁体   English

我怎么能在neo4j中写这个查询?

[英]How could I write this queries in neo4j?

I'm very new to neo4j and to graph database in general. 我对neo4j和图形数据库都很新。 I'm prototyping an app, and I don't know how should i write these queries 我是一个应用程序的原型,我不知道我应该如何编写这些查询

I've this domain: 我有这个域名:

User Restaurant Review TypeOfFood 用户餐厅评论TypeOfFood

So a Restarurant have one or many TypeOfFood, the User leaves reviews about restaurants. 因此,Restarurant有一个或多个TypeOfFood,用户留下关于餐馆的评论。 The User have some preferred foods, matching the TypeOfFood a restaurant sell. 用户有一些首选的食物,与餐馆出售的TypeOfFood相匹配。 Also Users are related to each other with the typically friend relationship. 此外,用户通常与朋友关系彼此相关。

Some of the queries I'm trying to write: 我正在尝试编写的一些查询:

  • Give me all the restaurants that my friends have rated with 3 or more stars that make the kind of food I like (exclude those restaurants that I already reviewed) 给我所有的朋友评价的餐厅用3颗或更多星星做成我喜欢的食物(不包括那些我已经评论过的餐馆)

  • Suggest me friends I may know (I guess this should be something like "all the friends that are friends of my friends but no yet mine, order by something) 建议我认识的朋友(我想这应该是“所有的朋友都是朋友的朋友,但还不是我的朋友,订购的东西)

Using Neo4j's Cypher query language you could write your queries like this: 使用Neo4j的Cypher查询语言,您可以编写如下查询:

Selecting the top-20 best rated restaurants, sorted by stars and number of reviews 选择排名前20位的最佳餐厅,按星级和评论数量排序

start user=(users,name,'Nico')
match user-[:FRIEND]->friend-[r,:RATED]->restaurant-[:SERVES]->food,
      user-[:LIKES]->food,user-[:RATED]->rated_by_me
where r.stars > 3
return restaurant.name, avg(r.stars), count(*)
order by avg(r.stars) desc, count(*) desc 
limit 20

Friends of a Friend 朋友的朋友

start user=(users,name,'Nico')
match user-[:FRIEND]->friend->[:FRIEND]->foaf
return foaf, foaf.name

You can execute these cypher queries in the Neo4j Webadmin Console on your dataset, but also in the neo4j-shell, remotely via the Cypher-Rest-Plugin via Spring Data Graph . 您可以在数据集的Neo4j Webadmin控制台中执行这些cypher查询,也可以在neo4j-shell中通过Spring Data Graph远程通过Cypher-Rest-Plugin执行这些查询。

There is also a screencast discussing similar queries in cypher. 还有一个截屏视频在cypher中讨论类似的查询。

You can also use Gremlin , Neo4j-Traversers or manual traversing via getRelationships if you'd like. 如果您愿意,也可以使用GremlinNeo4j-Traversers或通过getRelationships手动遍历。

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

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