简体   繁体   中英

Cypher query in a neo4j graph

I have the following graph in Neo4j:
Book : book_id, isbn, language_code, title, image_url, small_image_url, avg_ratings,
Author : name,
Reader : id,
with 3 relationships:
(Reader)-[:Rated]->(Book) that has the property {rating: value},
(Reader)-[:Recommend]->(Book) ,
(Author)-[:Write]->(Book) .

I want to find the book that has been most recommended with a query in Cypher.
I wrote a query but I'm not too sure about it because I'm not familiar using count() and max() operators.

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. I don't have your database, so I can't test this, but maybe this will work as a first stab at it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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