简体   繁体   English

neo4j 图中的 Cypher 查询

[英]Cypher query in a neo4j graph

I have the following graph in Neo4j:我在 Neo4j 中有以下图表:
Book : book_id, isbn, language_code, title, image_url, small_image_url, avg_ratings,图书:book_id、isbn、language_code、title、image_url、small_image_url、avg_ratings、
Author : name,作者:姓名,
Reader : id,读者:身份证,
with 3 relationships:有3个关系:
(Reader)-[:Rated]->(Book) that has the property {rating: value}, (Reader)-[:Rated]->(Book)具有属性 {rating: value},
(Reader)-[:Recommend]->(Book) , (Reader)-[:Recommend]->(Book) ,
(Author)-[:Write]->(Book) . (作者)-[:写]->(书)

I want to find the book that has been most recommended with a query in Cypher.我想在 Cypher 中找到最推荐的书。
I wrote a query but I'm not too sure about it because I'm not familiar using count() and max() operators.我写了一个查询,但我不太确定,因为我不熟悉使用 count() 和 max() 运算符。

Here is my attempt:这是我的尝试:

MATCH (r:Reader) - [rel:recommend] -> (b:Book) 
RETURN count(rel), b 
ORDER BY count 
LIMIT 1

I would try this:我会试试这个:

MATCH (:Reader) - [:recommend] -> (b:Book) 
RETURN 
    count(1) AS `Number of Recommendations`, 
    b AS `Book`
ORDER BY `Number of Recommendations` DESC
LIMIT 1

I would leave off the LIMIT clause until you make sure it's doing what you want.在你确定它正在做你想做的事情之前,我会放弃LIMIT子句。 I don't have your database, so I can't test this, but maybe this will work as a first stab at it.我没有你的数据库,所以我无法对此进行测试,但也许这将作为第一次尝试。

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

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